how to get the previous and next record if i know the current _id?

Visto 75 veces
Saltar al primer mensaje no leído

李玉北

no leída,
16 nov 2011, 7:51:3516/11/11
a mongod...@googlegroups.com
I'm using YiiMongoDbSuite in php, and i can fetch one record using the following code:
$record = MyModel::model()->findByAttributes(array(
  "key1" => "value1",
  "key2" => "value2",
  ...
));

but how can i get the previous record and next record use the similar conditions?

Thanks a lot.

Sam Millman

no leída,
16 nov 2011, 8:09:4016/11/11
a mongod...@googlegroups.com
I have not really used the Yii mongo suite for this, I instead built my own since I didn't agree with the authors programming.

However it should be pliable to a foreach():

foreach($records as $_id => $record){
  var _dump($record);
}

Should allow you to scroll through the records.

You can also use an array transferrer which will transfer the entire cursor to an array and scroll through it with default PHP functions.

I am not nsure what you mean by previous record but this will get the next record each time and if you are half way through a result set you will be able to get the previous record etc etc.

--
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To view this discussion on the web visit https://groups.google.com/d/msg/mongodb-user/-/VOK78bLXazAJ.
To post to this group, send email to mongod...@googlegroups.com.
To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.

Responder a todos
Responder al autor
Reenviar
0 mensajes nuevos