WriteConcernResult result null mongodb -
when trying update mongodb using below code result getting null: in c#
public bool updatecontact(string id, contact item) { imongoquery query = query.eq("_id", id); item.lastmodified = datetime.utcnow; imongoupdate update = update .set("email", item.email) .set("lastmodified", datetime.utcnow) .set("name", item.name) .set("phone", item.phone); writeconcernresult result = _contacts.update(query, update); homecoming result.updatedexisting; }
if you're not using new connection style c# driver (and other drivers), connection may configured not have writeconcern default.
if there's no writeconcern configured, c# api homecoming null
result code provided (see update more info)
for example, if connection this:
var connectionstring = "mongodb://localhost"; var server = mongoserver.create(connectionstring); // deprecated var database = server.getdatabase("test"); // writeconcern defaulted unacknowledged
that configured no write concern.
you should using style (as of c# 1.7 driver):
var connectionstring = "mongodb://localhost"; var client = new mongoclient(connectionstring); var server = client.getserver(); var database = server.getdatabase("test"); // writeconcern defaulted acknowledged
the difference need utilize mongoclient
class (and mongoserver
, mongodatabase
object instance).
mongodb
No comments:
Post a Comment