F
F
flov2018-08-21 09:37:57
JavaScript
flov, 2018-08-21 09:37:57

How to make mongodb javascript unload?

Good afternoon! it was necessary to unload the database from monga so that the separator was a semicolon, I found a working script in javascript (I don’t understand it myself). Now I need to unload a couple more collections, but I don’t know how to change the script so that everything works. please help if it's not difficult. =)

conn = new Mongo();
db = conn.getDB("artixcs");
var cur = db.shop.find();

var obj;
while(cur.hasNext()){
    obj = cur.next();
    print("\""+obj.displayCode+"\";\""+obj.address+"\"");
}

here the displayCode and address objects are unloaded in the shop collection, you need to somehow add the ip object from the cash collection.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan, 2018-08-21
@Iv_and_S

conn = new Mongo();// создаем объект БД
db = conn.getDB("artixcs"); // получаем БД
var cur = db.shop.find(); // находим коллекцию shop и ее в объект cur

var obj; // переменная хранения документа коллекции cur 
while(cur.hasNext()){ // итератор по коллекции , т.е. перебирает объекты и спрашивает " а не конец ли коллекции? и если не конец работает код ниже.                                      
    obj = cur.next(); // берем документ коллекции и его в переменную 
    print("\""+obj.displayCode+"\";\""+obj.address+"\""); //тут смотрим поля документа и печатаем
}

it remains to replace the values ​​\u200b\u200bof the variables with the ones you need and display as necessary

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question