Deleting an object inside another object in Mongodb and for GOlang - mongodb

I wanna delete a specific object inside an object, My object:
{
"_id" : ObjectId("5f577f3cce031ee00f5e32c9"),
"UserId" : 0,
"firstname" : "user 1",
"lastname" : "user 1",
"finishedTrainings" : [
{
"itemId" : 3,
"validationScore" : 1,
"timestamps" : {
"createdat" : ISODate("2020-09-09T12:57:31.275Z"),
"createdby" : 0,
"updatedat" : ISODate("0001-01-01T00:00:00Z"),
"updatedby" : 0
},
"isValidated" : true
},
{
"itemId" : 0,
"validationScore" : 0.6666666666666666,
"timestamps" : {
"createdat" : ISODate("2020-09-09T12:59:04.268Z"),
"createdby" : 0,
"updatedat" : ISODate("0001-01-01T00:00:00Z"),
"updatedby" : 0
},
"isValidated" : true
}
],
"biography" : ""
}
and I wanna delete the finishedTraining(id=3),what would be the syntax in mongodb

//code output from mongo shell 4.2, windows10
//data set as given in problem statement
> db.userTraining.find().pretty();
{
"_id" : ObjectId("5f577f3cce031ee00f5e32c9"),
"UserId" : 0,
"firstname" : "user 1",
"lastname" : "user 1",
"finishedTrainings" : [
{
"itemId" : 3,
"validationScore" : 1,
"timestamps" : {
"createdat" : ISODate("2020-09-09T12:57:31.275Z"),
"createdby" : 0,
"updatedat" : ISODate("0001-01-01T00:00:00Z"),
"updatedby" : 0
},
"isValidated" : true
},
{
"itemId" : 0,
"validationScore" : 0.6666666666666666,
"timestamps" : {
"createdat" : ISODate("2020-09-09T12:59:04.268Z"),
"createdby" : 0,
"updatedat" : ISODate("0001-01-01T00:00:00Z"),
"updatedby" : 0
},
"isValidated" : true
}
],
"biography" : ""
}
//assuming objectID is unique for the document, you can query your own business field
> db.userTraining.update(
... {_id:ObjectId("5f577f3cce031ee00f5e32c9")},
... {$pull:{"finishedTrainings":{itemId:3}}},
... false,
... true
... );
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
> db.userTraining.find().pretty();
{
"_id" : ObjectId("5f577f3cce031ee00f5e32c9"),
"UserId" : 0,
"firstname" : "user 1",
"lastname" : "user 1",
"finishedTrainings" : [
{
"itemId" : 0,
"validationScore" : 0.6666666666666666,
"timestamps" : {
"createdat" : ISODate("2020-09-09T12:59:04.268Z"),
"createdby" : 0,
"updatedat" : ISODate("0001-01-01T00:00:00Z"),
"updatedby" : 0
},
"isValidated" : true
}
],
"biography" : ""
}
>
//above id=3 is deleted object from the array, other document object remain intact by using "$pull" in the update statement

Related

Filter day on MongoDB

I have a collection called "batches" that has the field "createdAt" with ISODate:
{
"_id" : ObjectId("5f6134ecf908840018f2e9ea"),
"status" : "BATCH_PROCESSING",
"groupId" : 13,
"type" : "not",
"finished" : false,
"scheduledTo" : "2020-09-15T18:50:51-03:00",
"identifier" : "COLABORADORES",
"createdAt" : "2020-09-18T18:41:00-03:00",
"__v" : 0
}
{
"_id" : ObjectId("5f6144d7863bb40018045906"),
"status" : "BATCH_PROCESSING",
"groupId" : 13,
"type" : "not",
"finished" : false,
"scheduledTo" : "2020-09-16T19:48:00-03:00",
"identifier" : "COLABORADORES",
"createdAt" : "2020-09-15T19:48:55-03:00",
"__v" : 0
}
{
"_id" : ObjectId("5f617021b985c1001974c3af"),
"status" : "CANCELED",
"groupId" : 13,
"type" : "not",
"finished" : true,
"scheduledTo" : "2020-09-15T23:06:00-03:00",
"identifier" : "COLABORADORES",
"createdAt" : "2020-09-18T22:53:37-03:00",
"__v" : 0,
"numberOfLines" : 1
}
I need to filter only documents in a specific date. I tried many ways but it didn't bring the documents :
db.getCollection("batches").find(
{ createdAt : {
"$gte": ISODate("2020-09-15T00:00:00Z"),
"$lt": ISODate("2020-09-19T00:00:00Z")
} }
);
db.getCollection("batches").find({ createdAt : Date("2020-09-15")}
);
The query works well, but the answer is always:
Fetched 0 record(s) in 136ms
How do I do this filter correctly?
Your data is malformed. Your field 'createdDate' is a string, not an ISODate(). Consider this...
db.batches.insertMany([
{
"_id" : ObjectId("5f6134ecf908840018f2e9ea"),
"status" : "BATCH_PROCESSING",
"groupId" : 13,
"type" : "not",
"finished" : false,
"scheduledTo" : "2020-09-15T18:50:51-03:00",
"identifier" : "COLABORADORES",
"createdAt" : ISODate("2020-09-18T18:41:00-03:00"),
"__v" : 0
},
{
"_id" : ObjectId("5f6144d7863bb40018045906"),
"status" : "BATCH_PROCESSING",
"groupId" : 13,
"type" : "not",
"finished" : false,
"scheduledTo" : "2020-09-16T19:48:00-03:00",
"identifier" : "COLABORADORES",
"createdAt" : ISODate("2020-09-15T19:48:55-03:00"),
"__v" : 0
},
{
"_id" : ObjectId("5f617021b985c1001974c3af"),
"status" : "CANCELED",
"groupId" : 13,
"type" : "not",
"finished" : true,
"scheduledTo" : "2020-09-15T23:06:00-03:00",
"identifier" : "COLABORADORES",
"createdAt" : ISODate("2020-09-18T22:53:37-03:00"),
"__v" : 0,
"numberOfLines" : 1
}]
)
Query
When applying the query in your post...
db.getCollection("batches").find(
{ createdAt : {
"$gte": ISODate("2020-09-15T00:00:00Z"),
"$lt": ISODate("2020-09-19T00:00:00Z")
} })
... we now see the following results:
MongoDB Enterprise replSet:PRIMARY> db.getCollection("batches").find(
... { createdAt : {
... "$gte": ISODate("2020-09-15T00:00:00Z"),
... "$lt": ISODate("2020-09-19T00:00:00Z")
... } })
{ "_id" : ObjectId("5f6134ecf908840018f2e9ea"), "status" : "BATCH_PROCESSING", "groupId" : 13, "type" : "not", "finished" : false, "scheduledTo" : "2020-09-15T18:50:51-03:00", "identifier" : "COLABORADORES", "createdAt" : ISODate("2020-09-18T21:41:00Z"), "__v" : 0 }
{ "_id" : ObjectId("5f6144d7863bb40018045906"), "status" : "BATCH_PROCESSING", "groupId" : 13, "type" : "not", "finished" : false, "scheduledTo" : "2020-09-16T19:48:00-03:00", "identifier" : "COLABORADORES", "createdAt" : ISODate("2020-09-15T22:48:55Z"), "__v" : 0 }

Mongo Query Issue - Query records from two different collections and merge/join into one single record

I have two collections and From my queries , I got records from these collections as ,
Collection_A :
Query :
db.getCollection('Collection_A').findOne({"meta.md5":"270daaa8c9da2c0ce114fd297ecb3fce"},{"pdf":1,"_id":0})
Record :
{
"pdf" : {
"engine" : "pdf",
"status" : "done",
"retry" : 3,
"limit" : 4500,
"stop_on_detection" : 0,
"file_type" : "*",
"file_limit_slot" : 60,
"start_time" : 1543225534.08531,
"end_time" : 1543225534.90477,
"detection" : true
}
}
Collection_B:
Query :
db.getCollection('Collection_B').find({"md5":"270daaa8c9da2c0ce114fd297ecb3fce"},{"pdf":1,"_id":0})
Record :
{
"pdf" : {
"version" : {
"decomposer" : "1.0"
},
"results" : {
"status" : 1,
"vector_value" : 2,
"file_version" : "",
"is_portmanteau" : false,
"version" : {
"decomposer" : "1.0"
},
"pdfid" : {
"Encrypt" : 0,
"stream" : 2,
"JavaScript" : 1,
"OpenAction" : 1,
"JS" : 1,
"header" : "%PDF-1.1",
"entropy" : "",
"totalEntropy" : "",
"ObjStm" : 0,
"AcroForm" : 0,
"countEof" : "",
"xref" : 1,
"endobj" : 9,
"filename" : "270daaa8c9da2c0ce114fd297ecb3fce.pdf",
"version" : "0.2.1",
"AA" : 0,
"errorMessage" : "",
"Launch" : 0,
"RichMedia" : 0,
"endstream" : 2,
"nonStreamEntropy" : "",
"JBIG2Decode" : 0,
"trailer" : 1,
"isPdf" : "True",
"Page" : 1,
"countCharAfterLastEof" : "",
"dates" : {
"date" : []
},
"obj" : 9,
"EmbeddedFile" : 1,
"startxref" : 1,
"XFA" : 0,
"Colors" : 0,
"streamEntropy" : "",
"errorOccurred" : "False"
},
"file_id" : "ae9eb8ef543504666d2c4f58e1c2ff48",
"file_path" : "NA",
"pdf_id_error" : ""
},
"scan_duration" : 0.0714380741119385
}
}
How to merge these both records from these collections using a single query ? In SQL , I have used join to get data from two different tables. Since Im not familiar much with mongo , Not sure how to achieve this ?
Expected Result :
{
"pdf" : {
"status" : "Completed",
"detection" : true,
"pdf" : {
"version" : {
"decomposer" : "1.0"
},
"results" : {
"status" : 1,
"vector_value" : 2,
"file_version" : "",
"is_portmanteau" : false,
"version" : {
"decomposer" : "1.0"
},
"pdfid" : {
"Encrypt" : 0,
"stream" : 2,
"JavaScript" : 1,
"OpenAction" : 1,
"JS" : 1,
"header" : "%PDF-1.1",
"entropy" : "",
"totalEntropy" : "",
"ObjStm" : 0,
"AcroForm" : 0,
"countEof" : "",
"xref" : 1,
"endobj" : 9,
"filename" : "270daaa8c9da2c0ce114fd297ecb3fce.pdf",
"version" : "0.2.1",
"AA" : 0,
"errorMessage" : "",
"Launch" : 0,
"RichMedia" : 0,
"endstream" : 2,
"nonStreamEntropy" : "",
"JBIG2Decode" : 0,
"trailer" : 1,
"isPdf" : "True",
"Page" : 1,
"countCharAfterLastEof" : "",
"dates" : {
"date" : []
},
"obj" : 9,
"EmbeddedFile" : 1,
"startxref" : 1,
"XFA" : 0,
"Colors" : 0,
"streamEntropy" : "",
"errorOccurred" : "False"
},
"file_id" : "ae9eb8ef543504666d2c4f58e1c2ff48",
"file_path" : "NA",
"pdf_id_error" : ""
},
"scan_duration" : 0.0714380741119385
}
}
}
Update :
Tried This query :
db.getCollection('Collection_A').aggregate( [ { $match: {"meta.md5":"270daaa8c9da2c0ce114fd297ecb3fce"}}, { $lookup: {from: "Collection_B",localField: "meta.md5", foreignField: "md5", as: "pdf"}}, { $project: {"pdf.status":1,"pdf.detection":1,"_id":0}} ] )
But i'm getting this error from the robo mongo client
Failed to execute script.
Error:
Assert: command failed: {
"ok" : 0,
"errmsg" : "global.Collection_B cannot be sharded",
"code" : 28769,
"codeName" : "Location28769"
} : aggregate failed
_getErrorWithCode#src/mongo/shell/utils.js:25:13
doassert#src/mongo/shell/assert.js:16:14
assert.commandWorked#src/mongo/shell/assert.js:370:5
DBCollection.prototype.aggregate#src/mongo/shell/collection.js:1319:5
DBCollection.prototype.aggregate#:1:355
#(shell):1:1
Error: command failed: {
"ok" : 0,
"errmsg" : "global.Collection_B cannot be sharded",
"code" : 28769,
"codeName" : "Location28769"
} : aggregate failed :
_getErrorWithCode#src/mongo/shell/utils.js:25:13
doassert#src/mongo/shell/assert.js:16:14
assert.commandWorked#src/mongo/shell/assert.js:370:5
DBCollection.prototype.aggregate#src/mongo/shell/collection.js:1319:5
DBCollection.prototype.aggregate#:1:355
#(shell):1:1

MongoDB : lookup exact match without false rows

I have 3 tables :
accounts:[
{id:111,name:'john'},
{id:222,name:'due'}
]
workoutTypes:[
{id:1,title:'a'},
{id:2,title:'b'}
]
accountrecords:[
{_id:10,workoutTypeId:1,accountId:111},
{_id:11,workoutTypeId:1,accountId:222}
]
I used this command to group all account records by workout type that match to the current account like that:
db.workoutTypes.aggregate([
{
$lookup: {
from: "accountrecords",
localField: "_id",
foreignField: "workoutTypeId",
as: "records"
}
},
{
$match: {
$and: [
{ "records": { $ne: [] } },
{ "records.accountId": { $eq: mongoose.Types.ObjectId(accountId) } },
]
}
},
])
the issue that I'm getting the records that related to both of accounts.
saw that eq command return a false value for non-match values.
there is an option to get only the record that matches to current account?
First of all your localField on workoutTypes collection must be id, not _id. Probably a typo from your side. Secondly, you need to use $redact operator if you want to restrict the content. $match actually works as expected, but it actually isn't checking whether all your sub documents are satisfying the criteria.
Update:
Try this query:
db.workoutTypes.aggregate([
{
$lookup: {
from: "accountrecords",
localField: "_id",
foreignField: "workoutTypeId",
as: "records"
}
},
{$match:{"records.accountId":{$exists:true}, "records.accountId":{$eq:ObjectId("5a604b18280420c03e8d3a23")}}},
{$redact:{
$cond:{
if:{$or:[{$eq:["$accountId",ObjectId("5a604b18280420c03e8d3a23")]},{$not:"$accountId"}]},
then:"$$DESCEND",
else:"$$PRUNE"
}
}}
])
And the output is:
/* 1 */
{
"_id" : ObjectId("5ac8b2b8fb45830ff77cd33b"),
"updatedAt" : ISODate("2018-04-07T11:59:52.583Z"),
"createdAt" : ISODate("2018-04-07T11:59:52.583Z"),
"title" : "Snatch",
"__v" : 0,
"records" : [
{
"_id" : ObjectId("5acb1b666b08493b30deed92"),
"updatedAt" : ISODate("2018-04-09T07:51:02.294Z"),
"createdAt" : ISODate("2018-04-09T07:51:02.294Z"),
"accountId" : ObjectId("5a604b18280420c03e8d3a23"),
"workoutTypeId" : ObjectId("5ac8b2b8fb45830ff77cd33b"),
"repetition" : 4,
"weight" : 120,
"__v" : 0
},
{
"_id" : ObjectId("5acb1b6f6b08493b30deed93"),
"updatedAt" : ISODate("2018-04-09T07:51:11.878Z"),
"createdAt" : ISODate("2018-04-09T07:51:11.878Z"),
"accountId" : ObjectId("5a604b18280420c03e8d3a23"),
"workoutTypeId" : ObjectId("5ac8b2b8fb45830ff77cd33b"),
"repetition" : 5,
"weight" : 130,
"__v" : 0
},
{
"_id" : ObjectId("5ace23aa1c4d590dc049e94e"),
"updatedAt" : ISODate("2018-04-11T15:03:06.824Z"),
"createdAt" : ISODate("2018-04-11T15:03:06.824Z"),
"repetition" : 124,
"weight" : 32,
"accountId" : ObjectId("5a604b18280420c03e8d3a23"),
"workoutTypeId" : ObjectId("5ac8b2b8fb45830ff77cd33b"),
"__v" : 0
},
{
"_id" : ObjectId("5ace23b21c4d590dc049e94f"),
"updatedAt" : ISODate("2018-04-11T15:03:14.293Z"),
"createdAt" : ISODate("2018-04-11T15:03:14.293Z"),
"repetition" : 325,
"weight" : 235,
"accountId" : ObjectId("5a604b18280420c03e8d3a23"),
"workoutTypeId" : ObjectId("5ac8b2b8fb45830ff77cd33b"),
"__v" : 0
},
{
"_id" : ObjectId("5acc8ef5345125417cca18e3"),
"updatedAt" : ISODate("2018-04-10T10:16:21.709Z"),
"createdAt" : ISODate("2018-04-10T10:16:21.709Z"),
"repetition" : 123,
"weight" : 456,
"accountId" : ObjectId("5a604b18280420c03e8d3a23"),
"workoutTypeId" : ObjectId("5ac8b2b8fb45830ff77cd33b"),
"__v" : 0
}
]
}
/* 2 */
{
"_id" : ObjectId("5acdf56afd5ca008d01b706f"),
"updatedAt" : ISODate("2018-04-11T11:45:46.192Z"),
"createdAt" : ISODate("2018-04-11T11:45:46.192Z"),
"title" : "Jerk",
"__v" : 0,
"records" : [
{
"_id" : ObjectId("5acdf597fd5ca008d01b7070"),
"updatedAt" : ISODate("2018-04-11T11:46:31.674Z"),
"createdAt" : ISODate("2018-04-11T11:46:31.674Z"),
"repetition" : 12,
"weight" : 100,
"accountId" : ObjectId("5a604b18280420c03e8d3a23"),
"workoutTypeId" : ObjectId("5acdf56afd5ca008d01b706f"),
"__v" : 0
}
]
}
/* 3 */
{
"_id" : ObjectId("5ace336ed36c780e6ce76d5d"),
"updatedAt" : ISODate("2018-04-11T16:10:22.483Z"),
"createdAt" : ISODate("2018-04-11T16:10:22.483Z"),
"title" : "Weight lifting",
"__v" : 0,
"records" : [
{
"_id" : ObjectId("5ace337ed36c780e6ce76d5e"),
"updatedAt" : ISODate("2018-04-11T16:10:38.708Z"),
"createdAt" : ISODate("2018-04-11T16:10:38.708Z"),
"repetition" : 21,
"weight" : 100,
"accountId" : ObjectId("5a604b18280420c03e8d3a23"),
"workoutTypeId" : ObjectId("5ace336ed36c780e6ce76d5d"),
"__v" : 0
}
]
}
/* 4 */
{
"_id" : ObjectId("5ac8cf5ef14469169d8627e8"),
"updatedAt" : ISODate("2018-04-07T14:02:06.155Z"),
"createdAt" : ISODate("2018-04-07T14:02:06.155Z"),
"title" : "Double under",
"__v" : 0,
"records" : [
{
"_id" : ObjectId("5acc8f11345125417cca18e4"),
"updatedAt" : ISODate("2018-04-10T10:16:49.069Z"),
"createdAt" : ISODate("2018-04-10T10:16:49.069Z"),
"repetition" : 111111,
"weight" : 222222,
"accountId" : ObjectId("5a604b18280420c03e8d3a23"),
"workoutTypeId" : ObjectId("5ac8cf5ef14469169d8627e8"),
"__v" : 0
},
{
"_id" : ObjectId("5ace2d7b1c4d590dc049e950"),
"updatedAt" : ISODate("2018-04-11T15:44:59.722Z"),
"createdAt" : ISODate("2018-04-11T15:44:59.722Z"),
"weight" : 23,
"repetition" : 123555555,
"accountId" : ObjectId("5a604b18280420c03e8d3a23"),
"workoutTypeId" : ObjectId("5ac8cf5ef14469169d8627e8"),
"__v" : 0
}
]
}
/* 5 */
{
"_id" : ObjectId("5ac8cfdd79a48216b3e048b0"),
"updatedAt" : ISODate("2018-04-07T14:04:13.670Z"),
"createdAt" : ISODate("2018-04-07T14:04:13.670Z"),
"title" : "Push-ups",
"__v" : 0,
"records" : [
{
"_id" : ObjectId("5accc1f1cd58a407c6562f79"),
"updatedAt" : ISODate("2018-04-10T13:53:53.933Z"),
"createdAt" : ISODate("2018-04-10T13:53:53.933Z"),
"repetition" : 123,
"weight" : 456000,
"accountId" : ObjectId("5a604b18280420c03e8d3a23"),
"workoutTypeId" : ObjectId("5ac8cfdd79a48216b3e048b0"),
"__v" : 0
}
]
}
Now you just replace ObjectId("5a604b18280420c03e8d3a23") in the query with your mongoose code mongoose.Types.ObjectId(accountId) and you should be good now.

Issue with firebase query

My query:
let query = recentRef.queryOrderedByChild(FRECENT_GROUPID).queryEqualToValue(group_id)
query.observeSingleEventOfType(.Value, withBlock: { snapshot in
And database structure is :
And my query looks like:
(/Recent {
ep = fb343534ca520c70fe35b0a316ea8e4c;
i = groupId;
sp = fb343534ca520c70fe35b0a316ea8e4c;
})
and getting Snap (Recent) <null> when I print(snapshot).
Its strange that it was working fine but now its suddenly stopped working.
EDIT:
Complete JSON:
{
"Message" : {
"fb343534ca520c70fe35b0a316ea8e4c" : {
"-Kp0jed1EZ5BLllL5_cm" : {
"createdAt" : 1.500046597341153E9,
"groupId" : "fb343534ca520c70fe35b0a316ea8e4c",
"objectId" : "-Kp0jed1EZ5BLllL5_cl",
"senderId" : "lI6SRppSboScWo5xVjcfLL82Ogr2",
"senderName" : "Test1 Test1",
"status" : "",
"text" : "hi",
"type" : "text",
"updatedAt" : 1.50004659734136E9
}
}
},
"Recent" : {
"-Kp0jecwejhzQbbm62CW" : {
"counter" : 0,
"createdAt" : 1.500046600967624E9,
"description" : "Test1 Test1",
"groupId" : "fb343534ca520c70fe35b0a316ea8e4c",
"lastMessage" : "hi",
"members" : [ "lI6SRppSboScWo5xVjcfLL82Ogr2", "fnRvHFpaoDhXqM1se7NoTSiWZIZ2" ],
"objectId" : "-Kp0jecwejhzQbbm62CV",
"picture" : "",
"type" : "private",
"updatedAt" : 1.500046600967647E9,
"userId" : "fnRvHFpaoDhXqM1se7NoTSiWZIZ2"
},
"-Kp0jed-FU1PXt1iPr29" : {
"counter" : 0,
"createdAt" : 1.500046600971885E9,
"description" : "Srikant Root",
"groupId" : "fb343534ca520c70fe35b0a316ea8e4c",
"lastMessage" : "hi",
"members" : [ "lI6SRppSboScWo5xVjcfLL82Ogr2", "fnRvHFpaoDhXqM1se7NoTSiWZIZ2" ],
"objectId" : "-Kp0jed-FU1PXt1iPr28",
"picture" : "https://s3.amazonaws.com/top500golfdev/uploads/profile/srikant.yadav#rootinfosol.com/profilepicture.jpg",
"type" : "private",
"updatedAt" : 1.500046600971896E9,
"userId" : "lI6SRppSboScWo5xVjcfLL82Ogr2"
}
},
"User" : {
"fnRvHFpaoDhXqM1se7NoTSiWZIZ2" : {
"createdAt" : 1.500045753102713E9,
"email" : "srikant.yadav#rootinfosol.com",
"firstname" : "Srikant",
"fullname" : "Srikant Yadav",
"handle" : "Srikant",
"lastname" : "Yadav",
"networkImage" : "https://s3.amazonaws.com/top500golfdev/uploads/profile/srikant.yadav#rootinfosol.com/profilepicture.jpg",
"objectId" : "fnRvHFpaoDhXqM1se7NoTSiWZIZ2",
"online" : false,
"updatedAt" : 1.500045753102731E9
},
"lI6SRppSboScWo5xVjcfLL82Ogr2" : {
"createdAt" : 1.500045791892967E9,
"email" : "test1#gmail.com",
"firstname" : "Test1",
"fullname" : "Test1 Test1",
"handle" : "test1",
"lastname" : "Test1",
"networkImage" : "",
"objectId" : "lI6SRppSboScWo5xVjcfLL82Ogr2",
"online" : false,
"updatedAt" : 1.500046571456235E9
}
}
}

Why Using GeohayStack fail

I run this query in mongo shell, and successful get result
db.tablebusiness.find({ "LongitudeLatitude" : { "$near" : [106.772835, -6.186753], "$maxDistance" : 0.053980478460939611 }, "indexContents" : { "$all" : [/^warung/] } }).limit(2);
I got:
{
"_id" : "warung-nasi-nur-karomah__-6.19_106.78",
"BuildingID" : null,
"Title" : "Warung Nasi Nur Karomah",
"InBuildingAddress" : null,
"Building" : null,
"Street" : "Jl. Arjuna Utara No.35",
"Districts" : [],
"City" : "Jakarta",
"Country" : "Indonesia",
"LongitudeLatitudeFromGoogle" : null,
"DistanceFromGoogleAddress" : 0.0,
"Checkin" : 0,
"Note" : null,
"PeopleCount" : 0,
"Prominent" : 45.5,
"CountViews" : 0,
"StreetAdditional" : null,
"LongitudeLatitude" : {
"Longitude" : 106.775693893433,
"Latitude" : -6.18759540055471
},
"Rating" : {
"Stars" : 0.0,
"Weight" : 0.0
},
"Reviews" : [],
"ZIP" : null,
"Tags" : ["Restaurant"],
"Phones" : ["081380087011"],
"Website" : null,
"Email" : null,
"Price" : null,
"openingHour" : null,
"Promotions" : [],
"SomethingWrong" : false,
"BizMenus" : [],
"Brochures" : [],
"Aliases" : [],
"indexContents" : ["restaura", "estauran", "staurant", "taurant", "aurant", "urant", "rant", "ant", "nt", "t", "warung", "arung", "rung", "ung", "ng", "g", "nasi", "asi", "si", "i", "nur", "ur", "r", "karomah", "aromah", "romah", "omah", "mah", "ah", "h"]
}
But when I try this query with additional search multikey index I got nothing result
db.runCommand({ geoSearch : "tablebusiness", near : [106.772835, -6.186753], maxDistance : 0.053980478460939611, search : { "indexContents" : { "$all" : [/^warung/] } }, limit : 30 })
I got this
{
"results" : [ ],
"stats" : {
"time" : 0,
"btreeMatches" : 0,
"n" : 0
},
"ok" : 1
}
This is index in my collection database
[
{
"v" : 1,
"key" : {
"_id" : 1
},
"ns" : "isikotacobacoba.tablebusiness",
"name" : "_id_"
},
{
"v" : 1,
"key" : {
"LongitudeLatitude" : "2d",
"Prominent" : -1,
"indexContents" : 1
},
"ns" : "isikotacobacoba.tablebusiness",
"name" : "LongLat_Prominent_indexContents",
"dropDups" : false,
"background" : false
},
{
"v" : 1,
"key" : {
"LongitudeLatitude" : "2d",
"Prominent" : -1
},
"ns" : "isikotacobacoba.tablebusiness",
"name" : "LongLat_Prominent",
"dropDups" : false,
"background" : false
},
{
"v" : 1,
"key" : {
"indexContents" : 1
},
"ns" : "isikotacobacoba.tablebusiness",
"name" : "indexContents",
"dropDups" : false,
"background" : false
},
{
"v" : 1,
"key" : {
"LongitudeLatitude" : "2d",
"indexContents" : 1,
"Prominent" : -1
},
"ns" : "isikotacobacoba.tablebusiness",
"name" : "LongitudeLatitude__indexContents_1_Prominent_-1",
"bits" : 22
},
{
"v" : 1,
"key" : {
"Title" : 1
},
"ns" : "isikotacobacoba.tablebusiness",
"name" : "Title",
"dropDups" : false,
"background" : false
},
{
"v" : 1,
"key" : {
"City" : 1
},
"ns" : "isikotacobacoba.tablebusiness",
"name" : "City",
"dropDups" : false,
"background" : false
},
{
"v" : 1,
"key" : {
"LongitudeLatitude" : "geoHaystack",
"indexContents" : 1
},
"ns" : "isikotacobacoba.tablebusiness",
"name" : "LongitudeLatitude__indexContents_1",
"bucketSize" : 0.1
}
]
How format use runCommand mongoDB using geohaystack with additional field mulikey??
Geohaystack queries do not support arrays for the additional field,
only single values. The current implementation of geospatial indexes
and geohaystacks do not use the standard query and index code.
The examples from MongoDB's geohaystack documentation (
http://www.mongodb.org/display/DOCS/Geospatial+Haystack+Indexing )
only shows the additional field to be a simple single value, not an
array of values in a geohaystack query.