Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

got update working

  • Loading branch information...
commit 9316b4e25642b1d0c367fdc07e6a3a9aff2e4cd2 1 parent 051a51a
billy authored
Showing with 19 additions and 5 deletions.
  1. +14 −3 Mongo.cfc
  2. +5 −2 MongoDBTest.cfc
View
17 Mongo.cfc
@@ -18,8 +18,10 @@ collection = db.getCollection(collection_name);
function put(){
var doc = createObject('java', 'com.mongodb.BasicDBObject').init();
+ //var o = arguments[1];
if(arguments.size() eq 1){
doc.putAll(arguments[1]);
+ arguments[1]._id = doc.get("_id");
}
else {
doc.put(arguments[1],arguments[2]);
@@ -53,9 +55,18 @@ function delete(field,value){
} //end function
-function update(o){
- var q = createObject('java', 'com.mongodb.BasicDBObject').init(o);
- return collection.save(q);
+
+//ideally, we would have an object that when called would update itself
+//however, when working with structs, we need to tell MongoDB, which
+//item we want to update, since we are not maintaining the string id
+//in the structure.
+
+//update by object id ..._id
+function update(_id,o){
+ var obj = get("_id", _id);
+ var new_object = createObject('java', 'com.mongodb.BasicDBObject').init(o);
+ return collection.update(obj, new_object, false, false);
+
} //end function
View
7 MongoDBTest.cfc
@@ -51,9 +51,12 @@ function $updatePerson(){
mongo = createObject('component','Mongo');
id = mongo.put(person); //name/value or struct
person.name = 'ed';
- newperson = mongo.update(person);
+ newperson = mongo.update(id,person);
+ //debug(newperson.hashCode());
debug(newperson);
-
+ person._id = id.toString();
+ debug(person);
+ return;
mongo.delete('NAME','bill');
mongo.delete('NAME','ed');
Please sign in to comment.
Something went wrong with that request. Please try again.