skip to Main Content

Mongodb – Change element name from the result set of Mongo DB Query

I have collection like below named as "FormData", { "_id": ObjectId("5e3c27bf1ef77236945ef07b"), "eed12747-0923-4290-b09c-5a05107f5609": "20200206", "bd637691-782d-4cfd-8624-feeedfe11b3e": "[email protected]" } I have another collection named as "Form" which will have Title of Fields, { "_id": ObjectId("5e3c27bf1ef77236945ef07b"), "Fields":[ { "FieldID": "eed12747-0923-4290-b09c-5a05107f5609", "Title": "Phone" }, {…

VIEW QUESTION

MongoDB shell: how to remove all collections except list

I would like to remove all collections except a list. db.getCollectionNames().forEach(function(n){db[n].remove({})}); will remove all collections. db.getCollectionNames().filter(function(collection){return! /^((keepthisone)|(andthisone)|(alsokeepthisone))$/.test(collection)}); will list all the collections, except the ones I want to keep. How do I combine the two? db.getCollectionNames().filter(function(collection){return! /^((keepthisone)|(andthisone)|(alsokeepthisone))$/.test(collection)}).forEach(function(n){db[n].remove({})}); Does nothing.

VIEW QUESTION

Mongodb – Create an object to already existing collection

I have a collection "product_reviews" with this document structure { _id: 'B000000OE4', 'product/title': 'Working Class Hero', 'product/price': '16.99', reviews: [ { 'review/userId': 'unknown', 'review/profileName': 'unknown', 'review/helpfulness': '2/3', 'review/score': '4.0', 'review/time': '27/05/1999/00:00:00', 'review/summary': 'Worth it for one song', 'review/text': "I really…

VIEW QUESTION
Back To Top
Search