.Net Core MongoDB Driver InsertOne Index Error

Having trouble performing basic inserts of a document into a collection. Some details first:

  • Asp.Net Core
  • MongoDB.Driver 2.13
  • z/TPF Version 1.1
  • MongoDB Version 2.6.5

I’m trying to insert a document into a collection that does not contain a fixed ordinal address. There are documents in the collection that have unique “_id” fields, but the collection itself doesn’t have a fixed address.

I try to do the following:

                var document1 = new BsonDocument
                {
                    { "Key1", "test1" },
                    { "Key2", "test2"},
                    { "datetime", DateTime.Now },
                };

                try
                {
                    _mongoMsgDetailCollection4O.InsertOne(document1);
                }
                catch (MongoWriteException e)
                {
                    Console.WriteLine(e.Message);
                }

The error I get is:

Command Failed. MONG0018E 14.45.38 The _index field must exist in the input document.

How and where do I define this index in the input document? All the CRUD examples I’ve found don’t show having to define an index. Even if I define the index parameter in the document, I still get the same error.

                var document1 = new BsonDocument
                {
                    { "Key1", "test1" },
                    { "Key2", "test2"},
                    { "datetime", DateTime.Now },
                    {"_index", "SineInMsgCustom"}
                };

I am expecting that the document be inserted and that the ObjectId of the document can be retrieved to be recorded elsewhere in my application. Thanks for any help you can offer.

Hi @RKS ,

Similar to your earlier question, this error message appears to be coming from the API you are using.

MongoDB 2.6 was first released in March, 2014 and has been end of life since Oct, 2016. I’m not sure if 2.6.5 actually corresponds to a MongoDB server version or a version for the API you are using, but I would encourage you to upgrade to a more modern solution :).

The error message implies your document must have an _index field, but since adding that does not resolve the problem I would look into the API or code you are using that is leading to this error message.

I think you may be using IBM’s z/TPF MongoDB support. If so, I suggest looking into community or support options from IBM as this appears to be an emulation of some subset of the MongoDB API. We can’t provide relevant advice without knowing anything about the backend implementation, but the examples you have asked about so far suggest some novel constraints or behaviour compared to a genuine MongoDB deployment.

Regards,
Stennie