Reputation: 337
We have a document in mongoDB with key value pairs in which we have two columns "_id" and "value" column which looks like below:
{ "_id" : ObjectId("53cf9048b6e9e884602db85f"),
"value" : "Security ID:\t\tS-1-0-0\tAccount Name:\t\tKanav Narula\tAccount Domain:\t\tINDIA\t
}
Now we want to execute a query on value field. We want to extract Account Name and Account Domain from value field defined in the above document. Expected output:
{ "_id" : ObjectId("53cf9048b6e9e884602db85f"),
"value" : "Security ID:\t\tS-1-0-0\tAccount Name:\t\tKanav Narula\tAccount Domain:\t\tINDIA\t,
"Account Name" : Kanav Narula,
"Account Domain" : INDIA
}
can anyone suggest ways to perform this activity in mongoDB. Thanks in advance.
Upvotes: 1
Views: 331
Reputation: 2064
In order to make it searchable, the components of the Value string should have been separate fields, otherwise, Value is just a large string. The schema is wrong for what you are trying to do. Did you port it from Redis or some other key/value store? MongoDB is not a key/value store, you need to rethink your use case in a new light so to speak.
Upvotes: 0