[CSHARP-1421] Missing the generated ObjectId after inserting an object Created: 23/Sep/15  Updated: 23/Sep/15  Resolved: 23/Sep/15

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: 2.0.1
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Jürgen Stolz [X] Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

MongoDB 3.0
c# Sharp Driver 2.01 (Nuget)
Win8


Attachments: Text File Program.cs     File packages.config    

 Description   

After inserting an object into the database the genrated ObjectID isn´t returned.

In the google mongodb-csharp group exists a thread :InsertOneAsync(..) How do I get the ObjectId after insertion.

I included a main (VisualStudio 2013 console project) and the dependend packages.config



 Comments   
Comment by Jürgen Stolz [X] [ 23/Sep/15 ]

Sorry please close the jira. After changing the Class.Type from BsonDocument to the real Class.Type DBContentBase it worked.
original source code

        private static Task Insert(DBContentBase insertObject)
        {
..
            var collection = mongoDatabase.GetCollection<BsonDocument>(insertObject.GetType().Name);
            try
            {
                insertOneAsync = collection.InsertOneAsync(insertObject.ToBsonDocument());
            }
            catch (MongoWriteException e)
            {
..
            }
      }

modified source code

        private static Task Insert(DBContentBase insertObject)
        {
..
            var collection = mongoDatabase.GetCollection<DBContentBase>(insertObject.GetType().Name);
            try
            {
                insertOneAsync = collection.InsertOneAsync(insertObject);
            }
            catch (MongoWriteException e)
            {
..
            }
      }

Generated at Wed Feb 07 21:39:32 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.