NoRM - FindAndModify with arguments
Is it possible to specify fields while doing a FindAndModify, so only one field is returned?
Also, is it possible to do an upsert, to create the object if it doesn't exist.
As per: http://www.mongodb.org/display/DOCS/findAndModify+Command
I can't see any way of add开发者_Python百科ing the additional arguments
EDIT: Seems to be some confusion - I am using NoRM (C#) https://github.com/atheken/NoRM/
I'm afraid it's not possible actually in NoRM. You could fork the project and add an overloaded FindAndModify method to the file NoRM/Collections/MongoCollectionGeneric.cs to support this behavior.
I think you might need to add a field fields
in the anonymous object passed to findOne.
var returnValue = cmdColl.FindOne(new
{
findandmodify = this._collectionName,
query = query,
update = update,
sort = sort,
fields = fields
}).Value;
And maybe a pull request :)
Use the fields specifier. e.g.
db.foo.findAndModify({query:{_id:"myid"},
update:{$set:{priority:78}},new:true,fields:{_id:1,priority:1}})
精彩评论