summaryrefslogtreecommitdiff
path: root/node
diff options
context:
space:
mode:
authoradam <anton@adamansky.com>2013-01-09 17:26:21 +0700
committeradam <anton@adamansky.com>2013-01-09 17:26:21 +0700
commit73961fb45798b6c947e1a10c90d38cadce2a6665 (patch)
treee8fe67d205ea1c94133221844a36b88dfee3521e /node
parenteef1536428ff7dee8c680903e7952f1f90ebbd96 (diff)
downloadejdb-73961fb45798b6c947e1a10c90d38cadce2a6665.tar.gz
ejdb-73961fb45798b6c947e1a10c90d38cadce2a6665.tar.bz2
ejdb-73961fb45798b6c947e1a10c90d38cadce2a6665.zip
v1.0.45 #32
Diffstat (limited to 'node')
-rw-r--r--node/ejdb_native.cc22
m---------node/nodejs0
-rw-r--r--node/tests/t2.js16
3 files changed, 33 insertions, 5 deletions
diff --git a/node/ejdb_native.cc b/node/ejdb_native.cc
index d50f72d..bea95cc 100644
--- a/node/ejdb_native.cc
+++ b/node/ejdb_native.cc
@@ -1374,13 +1374,25 @@ namespace ejdb {
TCLIST *res = NULL;
bson oqarrstack[8]; //max 8 $or bsons on stack
BSONQCmdData *cmdata = task->cmd_data;
+ std::vector<bson*> &bsons = cmdata->bsons;
EJCOLL *coll = ejdbgetcoll(m_jb, cmdata->cname.c_str());
- if (!coll) { //No collection -> no results
- cmdata->res = tclistnew2(1);
- cmdata->count = 0;
- return;
+ if (!coll) {
+ bson *qbs = bsons.front();
+ bson_iterator it;
+ //If we are in $upsert mode so new collection will be created
+ if (qbs && bson_find(&it, qbs, "$upsert") == BSON_OBJECT) {
+ coll = ejdbcreatecoll(m_jb, cmdata->cname.c_str(), NULL);
+ if (!coll) {
+ task->cmd_ret = CMD_RET_ERROR;
+ task->cmd_ret_msg = _jb_error_msg();
+ return;
+ }
+ } else { //No collection -> no results
+ cmdata->res = tclistnew2(1);
+ cmdata->count = 0;
+ return;
+ }
}
- std::vector<bson*> &bsons = cmdata->bsons;
int orsz = (int) bsons.size() - 2; //Minus main qry at begining and hints object at the end
if (orsz < 0) orsz = 0;
bson *oqarr = ((orsz <= 8) ? oqarrstack : (bson*) malloc(orsz * sizeof (bson)));
diff --git a/node/nodejs b/node/nodejs
-Subproject b00527fcf05c3d9fb5d5d790f9472906a59fe21
+Subproject 1c9c6277d5cfcaaac8569c0c8f7daa64292048a
diff --git a/node/tests/t2.js b/node/tests/t2.js
index bbb1a1f..918d810 100644
--- a/node/tests/t2.js
+++ b/node/tests/t2.js
@@ -422,6 +422,22 @@ module.exports.testTx1 = function(test) {
});
};
+module.exports.testCreateCollectionOn$upsert = function(test) {
+ test.ok(jb);
+ test.ok(jb.isOpen());
+ jb.update("upsertcoll", {foo : "bar", $upsert : {foo : "bar"}}, function(err, count) {
+ test.ifError(err);
+ test.equal(count, 1);
+ jb.findOne("upsertcoll", {foo : "bar"}, function(err, obj) {
+ test.ifError(err);
+ test.ok(obj);
+ test.equal(obj.foo, "bar");
+ test.done();
+ });
+ });
+};
+
+
module.exports.testClose = function(test) {
test.ok(jb);
jb.close();