Your first issue is just a typo. Change "subDocList.userid" to
"subDocList.userId" and you should be good.
For the second issue, you have 2 options. The first is to change
userId to an ObjectIdField. Your query will work as is if you do this.
The second option is to change how you build your query. Instead of
using the JsonDSL, use com.mongodb.QueryBuilder and pass in the String
value of the ObjectId. This way it won't get converted to an actual
ObjectId.
Tim
> --
> You received this message because you are subscribed to the Google Groups
> "Lift" group.
> To post to this group, send email to lif...@googlegroups.com.
> To unsubscribe from this group, send email to
> liftweb+u...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/liftweb?hl=en.
>
1-2: Every String that passes through JObjectParser (JsonObjects) is
tested to see if it is a valid ObjectId using ObjectId.isValid. If it
is it's transformed to an ObjectId. At the time I wrote this, that was
the only way I could figure out to handle ObjectIds, which is required
for MongoDocument. Unfortunately, those that wrote their apps with
this convention rely on this behavior. I do have a patch up on
reviewboard that will allow for a better way to handle this, but we
decided to leave the isValid checks in for backwards compatibility.
3. This is the default MongoDB behavior. If you want to make sure the
update happened correctly, you have to call getLastError directly on
the database. This is what MongoDB.useSession is for, the call to
getLastError must be on the same thread that your update is on,
useSession ensures that. There is a save function that you can use
that will throw an exception, if there was an error. You just need to
call it with save(true) to turn on strict-mode. See [1] for more info
on getLastError. This is the save function for reference:
def save(inst: BaseRecord, strict: Boolean): Boolean = saveOp(inst) {
if (strict) // strict mode will call getLastError and throw an
exception if there was an error
MongoDB.useSession(mongoIdentifier) {
db =>
val coll = db.getCollection(collectionName)
coll.setWriteConcern(DB.WriteConcern.STRICT)
coll.save(inst.asDBObject)
coll.setWriteConcern(DB.WriteConcern.NORMAL)
}
else
MongoDB.useCollection(mongoIdentifier, collectionName) {
coll => coll.save(inst.asDBObject)
}
}
Tim
1 - http://www.mongodb.org/display/DOCS/Last+Error+Commands