From 106de70ace71f3cfb2a6d2461c01e173eeba773e Mon Sep 17 00:00:00 2001 From: Richard Louapre Date: Mon, 10 Dec 2012 07:42:38 -0500 Subject: [PATCH] Example for issue #42 Small example on how to use "script filters" --- resources/issues/42/01_create-river.bat | 1 + resources/issues/42/02_test-issue-42.bat | 8 ++++++++ .../issues/42/mongodb-river-script-filters.json | 12 ++++++++++++ resources/issues/42/test-issue-42-import-document.js | 10 ++++++++++ resources/issues/42/test-issue-42-update-document.js | 4 ++++ 5 files changed, 35 insertions(+) create mode 100644 resources/issues/42/01_create-river.bat create mode 100644 resources/issues/42/02_test-issue-42.bat create mode 100644 resources/issues/42/mongodb-river-script-filters.json create mode 100644 resources/issues/42/test-issue-42-import-document.js create mode 100644 resources/issues/42/test-issue-42-update-document.js diff --git a/resources/issues/42/01_create-river.bat b/resources/issues/42/01_create-river.bat new file mode 100644 index 00000000..ceddb864 --- /dev/null +++ b/resources/issues/42/01_create-river.bat @@ -0,0 +1 @@ +curl -XPUT "http://localhost:9200/_river/mongodb42/_meta" -d @mongodb-river-script-filters.json \ No newline at end of file diff --git a/resources/issues/42/02_test-issue-42.bat b/resources/issues/42/02_test-issue-42.bat new file mode 100644 index 00000000..a09d1114 --- /dev/null +++ b/resources/issues/42/02_test-issue-42.bat @@ -0,0 +1,8 @@ +%MONGO_HOME%\bin\mongo < test-issue-42-import-document.js +pause +curl -XGET localhost:9200/mydb-42/_search?q=firstName:John42 +pause +%MONGO_HOME%\bin\mongo < test-issue-42-update-document.js +pause +curl -XGET localhost:9200/mydb-42/_search?q=firstName:John42 +pause \ No newline at end of file diff --git a/resources/issues/42/mongodb-river-script-filters.json b/resources/issues/42/mongodb-river-script-filters.json new file mode 100644 index 00000000..0a729b4f --- /dev/null +++ b/resources/issues/42/mongodb-river-script-filters.json @@ -0,0 +1,12 @@ +{ + "type": "mongodb", + "mongodb": { + "db": "mydb", + "collection": "mycollec", + "script": "if( ctx.document.state == 'CLOSED' ) { ctx.deleted = true; }" + }, + "index": { + "name": "mydb-42", + "type": "mycollec-42" + } +} \ No newline at end of file diff --git a/resources/issues/42/test-issue-42-import-document.js b/resources/issues/42/test-issue-42-import-document.js new file mode 100644 index 00000000..41b3f681 --- /dev/null +++ b/resources/issues/42/test-issue-42-import-document.js @@ -0,0 +1,10 @@ +use mydb +var o = +{ + "firstName": "John42", + "lastName": "Doe42", + "age": 34, + "state": "OPENED" +} + +db.mycollec.save(o) \ No newline at end of file diff --git a/resources/issues/42/test-issue-42-update-document.js b/resources/issues/42/test-issue-42-update-document.js new file mode 100644 index 00000000..4a9c9215 --- /dev/null +++ b/resources/issues/42/test-issue-42-update-document.js @@ -0,0 +1,4 @@ +use mydb +var o = db.mycollec.findOne({"firstName": "John42", "lastName": "Doe42"}) +o.state = 'CLOSED'; +db.mycollec.save(o) \ No newline at end of file