Hi -
I am tring to work with the mongodb client (nimble install nimongo) but I am not able to get the introductory example in the nimongo github distrubtion to work.
It gives an error here:
var m = newMongo().slaveOk(true).allowPartial(false)
the compilation error is as follows:
Error: type mismatch: got <MongoBase> but expected one of: proc connect(am: AsyncMongo): Future[bool] proc connect(m: Mongo): bool
I can succeed in getting a connection with this instead:
var m = newMongo()
and I can insert one doc with the insert statement below:
## Connect to Mongo server > let connectResult = m.connect() > ## Specify collection > let collection = m["db"]["collectionName"] > ## Create new bson document > let doc = %*{ > "name": "John" > } > ## Insert document into DB > collection.insert(doc)
However after this insertion when I try to update, it fails here,
## Create new bson document > let doc = B(name, "John") > ## Update [single] document > collection.update(B("name", "John"), B("$set", B("surname", "Smith")))
The compilation with this update code is failing with this message:
Error: undeclared identifier: 'name'
Any ideas on how to proceed?
Thanks.
let doc = B(name, "John")
should be
let doc = B("name", "John".toBson)
From the source, it needs a string and BSON https://github.com/SSPkrolik/nimongo/blob/master/nimongo/bson.nim#L502-L505
Thank you. Your revision works.
let doc = B("name", "John".toBson)
Yet the mongo update attempt in the subsequent line below doesn't work:
collection.update(B("name", "John"), B("$set", B("surname", "Smith")))
Following your hint I tried,
collection.update(B("name", "John".toBson), B("$set", B("surname", "Smith".toBson)))
but this doesn't work.
BTW, I went back to the two given github examples from,
https://github.com/SSPkrolik/nimongo
for synchronous case and asynchronous case respectively. Both these examples are failing too. Guess we have to wait a while for this driver to stabilize.
use
collection.update(B("name", "John".toBson), B("$set", B("surname", "Smith".toBson)), false, false)
update needs 5 arguments instead of only 3 https://github.com/SSPkrolik/nimongo/blob/master/nimongo/mongo.nim#L650-L669