Open DenQ opened 7 years ago
If you use the findOne
method of Collection
, without a specified query, the last inserted document should be retrieved.
I see that the MongoDB driver for node provides a way of retrieving this information using the callback of insert
: http://mongodb.github.io/node-mongodb-native/2.2/api/Collection.html#insert
I will look into supporting that in the next version of ZangoDB.
Thank you
Thanks for fast answer.
I have tried work with .findOne()
, but he give first element from collection.
But, I got last element so
collection.insert(docs)
.then(() => {
return collection.find().sort({_id: -1}).limit(1).toArray(); //last element wrap array
// return collection.findOne(); // first element
})
Good job. Also, I will send a message when the alternative approach is completed.
Hello. How I can get last added document or last id? I waited similar - https://github.com/dfahlander/Dexie.js/blob/master/samples/react-redux/src/actions/index.js#L27