Czy ktoś może mi pomóc z tym problemem związanym ze sterownikiem MongoDB C #:
Mam pole, które aktualizuje się automatycznie wraz z datą z serwera. Ale działa tylko wtedy, gdy aktualizuję dokument.
To działa (ponieważ jest aktualizacja (?)):
IMongoUpdate update = new UpdateDocument(new BsonDocument().Add("$currentDate", new BsonDocument().Add("lastModified", true)
.Add("lastModifiedTS", new BsonDocument("$type", "timestamp"))).Add(new BsonDocument()
.Add("$set", new BsonDocument().Add("altered", alteredElementValue))));
var updateResult = _collection.Update(Query.EQ("_id", key), update);
To nie działa (to jest wstawka):
_collection.Save(bson.First().Add(new UpdateDocument(new BsonDocument().Add("$currentDate", new BsonDocument().Add("lastModified", true)
.Add("lastModifiedTS", new BsonDocument("$type", "timestamp"))))));
Ale kiedy wstawiam dokument, pojawia się następujący błąd:
A first chance exception of type "MongoDB.Driver.WriteConcernException" occurred in MongoDB.Driver.dll
Additional information: WriteConcern detected an error
"The dollar ($) prefixed field "$currentDate" in "$currentDate" is not valid for storage.".
(Response was { "ok" : 1, "code" : 52, "err" : "The dollar ($) prefixed field "$currentDate" in "$currentDate" is not valid for storage.", "n" : NumberLong(0), "updatedExisting" : false }).
Czy może być tak, ponieważ MOngoDB obsługuje tego rodzaju pola tylko w celu aktualizacji?
Odpowiedzi:
0 dla odpowiedzi № 1Tak masz rację. To błąd. MongoDb nie obsługuje $currentDate
dla insert
: https://jira.mongodb.org/browse/SERVER-13695