开发者

NoRM - FindAndModify with arguments

开发者 https://www.devze.com 2023-02-13 01:17 出处:网络
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.

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}})
0

精彩评论

暂无评论...
验证码 换一张
取 消