Been working with MDBC powershell module to connect to MongoDB instance in Azure cosmosDB. Need to load a .js file with the code to update the collections..
Example:(mikesSuperHappyJS.js)
var collection = 'MikesContext';
use('HappyMongoDBStuff);
db[collection].drop();
db.createCollection(collection);
db[collection].createIndex({ MarketId: 1 });
db[collection].insert({
"_id": "9875309",
"_t": "MikesContext",
"MikesId": 98457,
"MikesName": "Mike",
"UWGuideLink": "https://mikedopp.com/funnyman.pdf",
"KnowledgeBaseLink": ""
});
would love to use
MongoDB "load(file)" or Load(mikesSuperHappyJS.js) to import this very important .js file.
However Im not finding a way to do such a thing. https://www.mongodb.com/docs/v5.0/reference/method/load/
used mdbc to do the powershell module work but cant find a "easy" way to just load the .js file. Any suggestions?
The
load()seems is a method in the MongoDB Shell and not available for MDBC PowerShell module.To use the
load()method in PowerShell, you can try with the following steps:Download and install MongoDB Shell (
mongosh.exe) on the agent machine.On PowerShell, you first need to run the
mongoshcommand to connect to your MongoDB deployment.Then you can run the following command with the
load()method to load and execute the.jsfile.For more details, you can see "Write Scripts - MongoDB Shell".