2

There's a MongoDB collection that was populated with documents like this one:

{
    "_id" : ObjectId("5b7f83b591fae49715443590"),
    "content" : "{\n\t\"email\":\"[email protected]\",\n\t\"country_code\": \"US\"\n}"
}

As you can see "content"has a JSON string

I was able to parse the string using JSON.parse() like:

db.getCollection('my_collection').find({}).map(function(doc){ return {'_id':doc._id, 'content': JSON.parse(doc.content)}});

Giving me an array of objects with _id and content as an object.

Is there a way to execute queries (filtering, aggregate functions) over content preferably without getting an array from map?

1 Answer 1

2

like you said In terms of the database content is a string. So you need to save the entire collection where content will be a object so you will be able to filtering, aggregate etc...

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.