2

After using insertMany I need to get the returned _ids from the new documents in the same order as they were inserted.

As stated by the documentation if the ordered parameter is equal to true, mongoDB will perform an ordered insert, but that does not imply that the returned _ids are also ordered in the same way as the new inserted documents.

I did some quick tests to check this and it seems that the order is preserved, but I need to be 100% sure that this is always the behavior.

lgvaz
  • 452
  • 6
  • 17
  • If the documentation says explicitly that ordering is not guaranteed, you shouldn't assume that it will be – rdas Apr 06 '19 at 05:13
  • The documentation doesn't say that ordering is not guaranteed, it simply doesn't mention it at all. Maybe I'm just being paranoid here, because the documentation says that the docs will be inserted in order, so it's logical to think that the returned _ids are also going to be ordered. – lgvaz Apr 06 '19 at 05:24
  • In that case, yes it makes sense that the documents ids are in insertion order – rdas Apr 06 '19 at 05:26

0 Answers0