Insert raw JSON into MongoDB

Is there a way to insert JSON directly into MongoDB, without converting to a POJSO first?

Something like:

const myJSON = '{"foo":"bar"}';

db.collection.insert(myJSON, {raw:true}, (err, result) => {});

does anyone know how to do this? I am trying to avoid calling JSON.parse() on a JSON string only to have to serialized immediately afterward by the MongoDB driver.

1 answer

  • answered 2019-09-10 02:37 Ashok

    For insert raw json you need to add field name on which raw json store

    db.collection.insert({ rawJason: myJSON }, { raw: true }, (err, data) => {})

    { raw: true } is optional