FindAndModify with $inc modifier

72 views
Skip to first unread message

Kenichi Sugihara

unread,
Aug 4, 2010, 3:22:34 AM8/4/10
to mongodb...@googlegroups.com
Now I'm trying to implement sequence function with FindAndModify(), but
I've got the following command in FindAndModify().

command:
{"findandmodify": "Sequence", "query": {"...."}, "update": { "$set":
{"$inc": {"Sequence":1}}}, "sort": {}, "new": true}

To increment "Sequence" is what I want to do, but generated command for
updating document is {"$set":{"$inc":{"Sequence":1}}}.
The codes which call FindAndModify() are as followings.

var col = Database.GetCollection<Sequence>();
var next = col.FindAndModify(new Document("$inc", new
Document("Sequence", 1)), selectorDocumentObject, true);

Am I misunderstanding how to use FindAndModify() or is it bug ?

FYI.

MongoDB version is 1.4.4 and MongoDB-CSharp driver is built on my own
which has been downloaded 3 days before.

Any suggestions is appreciated.

Kenichi Sugihara

unread,
Aug 4, 2010, 3:56:43 AM8/4/10
to mongodb...@googlegroups.com

Digging EnsureUpdateDocument at MongoCollection_1.cs, I've found it will
process as expected if descriptor is DocumentObjectDescriptorAdapter.
To do so, I've modify code as followings.

-- var descriptor =
_configuration.SerializationFactory.GetObjectDescriptor(typeof(T));
++ var descriptor =
_configuration.SerializationFactory.GetObjectDescriptor(document.GetType());

As a result of the above modification, 'update document' doesn't become
to be wrapped by 'set'.
But I don't know whether this modification is collect.

Thanks.

Steve Wagner

unread,
Aug 10, 2010, 1:25:27 PM8/10/10
to mongodb...@googlegroups.com
It looks like this is a bug. I will try to look into this later.

craiggwilson

unread,
Aug 10, 2010, 1:34:45 PM8/10/10
to mongodb-csharp
I don't think the fix is correct, because we need the descriptor for
typeof(T) and not for the document type. However, I do think this may
be a bug with FindAndModify.

Kenichi Sugihara

unread,
Aug 10, 2010, 8:53:24 PM8/10/10
to mongodb...@googlegroups.com

Thanks.
Reply all
Reply to author
Forward
0 new messages