if (!jsarr) {
return;
}
- if (!cb) {
- cb = function() {
- };
- }
if (jsarr.constructor !== Array) {
jsarr = [jsarr];
}
- return this._impl.save(cname, jsarr, cb);
+ return this._impl.save(cname, jsarr, function(err, oids) {
+ if (err) {
+ if (cb) {
+ cb(err);
+ }
+ return;
+ }
+ //Assign _id property for newly created objects
+ for (var i = jsarr.length - 1; i >= 0; --i) {
+ var so = jsarr[i];
+ if (so != null && so["_id"] !== oids[i]) {
+ so["_id"] = oids[i];
+ }
+ }
+ if (cb) {
+ cb(err, oids);
+ }
+ });
};
"age" : 15,
"likes" : ["sugar cane"]
};
- jb.save("parrots", [parrot1, parrot2], function(err, oids) {
+ jb.save("parrots", [parrot1, null, parrot2], function(err, oids) {
test.ifError(err);
test.ok(oids);
- test.equal(oids.length, 2);
+ test.equal(oids.length, 3);
+ test.equal(parrot1["_id"], oids[0]);
+ test.ok(oids[1] == null);
+ test.equal(parrot2["_id"], oids[2]);
test.done();
});
};