No matching document found

1,337 views
Skip to first unread message

Richard Bateman

unread,
Sep 13, 2012, 4:02:56 PM9/13/12
to mongoo...@googlegroups.com

We recently updated to the 3.1.x branch and are using 3.1.2 from npm. I noticed recently that some of our models are now behaving a little oddly; every time I save after changing an array from our document I get the error "No matching document found". The weirdest thing, though, is that it still saves the document.

Doing a little research it looks like this could be related to versioning, but nothing else is changing that document while I'm doing this (it's local on my dev box currently). Also the fact that it saves anyway but throws an error is really odd.

Any ideas?

Richard

Aaron Heckmann

unread,
Sep 13, 2012, 5:30:34 PM9/13/12
to mongoo...@googlegroups.com
Odd indeed. Would you mind opening an issue with code to reproduce?

https://github.com/LearnBoost/mongoose/issues/new
> --
> --
> http://mongoosejs.com - docs
> http://plugins.mongoosejs.com - plugins search
> http://github.com/learnboost/mongoose - source code
>
> You received this message because you are subscribed to the Google
> Groups "Mongoose Node.JS ORM" group.
> To post to this group, send email to mongoo...@googlegroups.com
> To unsubscribe from this group, send email to
> mongoose-orm...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/mongoose-orm?hl=en
>
>

Richard Bateman

unread,
Sep 24, 2012, 4:29:10 PM9/24/12
to mongoo...@googlegroups.com

I think by the time I could easily build something to repro it I could probably fix it. Do you mind telling me where to start looking and I'll see if I can track it down myself? We will have to revert back to 2.x if I can't track this down soon; it's happening any time we update an array by assignment. I haven't yet verified if using .push, etc works.

Richard

Richard Bateman

unread,
Sep 24, 2012, 4:38:11 PM9/24/12
to mongoo...@googlegroups.com

Okay, I found one of the issues was caused by two saves called in the same request. The first only changes one field and it's not an array, the second changes an array. Not sure why it should matter which occurs first since they dont' modify the same parts of the document; any thoughts? One is just updating a "last seen" timestamp and it's in our middleware and doesn't know about other modifications that might need to be made.

Richard

On Sep 13, 2012, at 3:30 PM, Aaron Heckmann wrote:

Aaron Heckmann

unread,
Oct 1, 2012, 5:25:44 PM10/1/12
to mongoo...@googlegroups.com
It would be nice to have code to test.

"No matching document found" comes when attempting to make changes to
an array by index position and the documents version already changed
in the db. http://aaronheckmann.posterous.com/mongoose-v3-part-1-versioning

You can disable versioning (not recommended) by setting your schema
option: new Schema({..}, { versionKey: false })
Aaron
@aaronheckmann

Richard Bateman

unread,
Oct 2, 2012, 4:34:14 PM10/2/12
to mongoo...@googlegroups.com

I'll see if I can find time to throw something together. The other issue turned out to be a document that was mistakenly saved twice in a row.

Does the version change *every* time the document is updated, or only when changes are made to an array?

Richard

Aaron Heckmann

unread,
Oct 2, 2012, 4:48:02 PM10/2/12
to mongoo...@googlegroups.com
On Tue, Oct 2, 2012 at 1:34 PM, Richard Bateman <ric...@batemansr.us> wrote:
> Does the version change *every* time the document is updated, or only when changes are made to an array?

Whenever changes are made to the array.

--
Aaron
@aaronheckmann

Richard Bateman

unread,
Oct 2, 2012, 5:51:01 PM10/2/12
to mongoo...@googlegroups.com

Hmm. Basically in my case there are two saves happening in the same web request, without waiting for the first to finish. Since the first only changes one field and it is *not* part of an array, then the second would have to be finishing first before such an error would occur if that is the case.

I'll have to see if I can create an isolated test case to repro the issue.

Richard

Aaron Heckmann

unread,
Oct 2, 2012, 5:55:40 PM10/2/12
to mongoo...@googlegroups.com
sounds good
--
Aaron
@aaronheckmann
Reply all
Reply to author
Forward
0 new messages