Alonetech
Alonetech

Reputation: 69

How to create a collection from JSON data in MongoDB?

I have the following J SON data. How to sum balance of the following collection?

"_id" : ObjectId("592595a1bca1350220027666"),
"user_account" : "5-5XX4XX-X06",
"Xns" : {
        "Xn" : [
                {
                        "date" : "2015-09-01",
                        "narration" : "ATM/CASH WDL/01-01-10/17:48:45/0",
                        "amount" : "-2500.00",
                        "category" : "Others",
                        "balance" : "110578.04",
                        "_id" : ObjectId("592595a1bca13502200276ca")
                },
                {
                        "date" : "2015-09-04",
                        "narration" : "EBA//20100104081107",
                        "amount" : "-7206.12",
                        "category" : "Others",
                        "balance" : "103371.92",
                        "_id" : Object Id("592595a1bca13502200276c9")
                }

Upvotes: 0

Views: 7643

Answers (2)

helpdoc
helpdoc

Reputation: 1990

You can do it by :

mongoimport --db <db-name> --collection <collection-name> --file ~/location/<file-name>.json

Upvotes: 3

Sercan Ozdemir
Sercan Ozdemir

Reputation: 4691

MongoDB offers mongoimport tool for that. For example:

mongoimport -c people -d example --mode upsert --file people-20160927.json

C for collection, D for database. Read more here And don't forget your JSON should be a valid extended JSON

Upvotes: 0

Related Questions