Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 90ebfc3

Browse files
Create generate-dummy-data-in-monodb.md
1 parent 4d3da6c commit 90ebfc3

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

‎generate-dummy-data-in-monodb.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
enter mongo shell and create transactions db:
2+
3+
```
4+
$ mongo
5+
> use transactions
6+
```
7+
8+
Create a function to generate random data:
9+
10+
```
11+
> var txs = []
12+
> for (var x = 0; x < 1000 ; x++) {
13+
var transaction_types = ["credit card", "cash", "account"];
14+
var store_names = ["edgards", "cna", "makro", "picknpay", "checkers"];
15+
var random_transaction_type = Math.floor(Math.random() * (2 - 0 + 1)) + 0;
16+
var random_store_name = Math.floor(Math.random() * (4 - 0 + 1)) + 0;
17+
txs.push({
18+
transaction: 'tx_' + x,
19+
transaction_price: Math.round(Math.random()*1000),
20+
transaction_type: transaction_types[random_transaction_type],
21+
store_name: store_names[random_store_name]
22+
});
23+
}
24+
```
25+
26+
Write the data to a collection:
27+
28+
```
29+
> db.purchases.insert(txs)
30+
BulkWriteResult({
31+
"writeErrors" : [ ],
32+
"writeConcernErrors" : [ ],
33+
"nInserted" : 1000,
34+
"nUpserted" : 0,
35+
"nMatched" : 0,
36+
"nModified" : 0,
37+
"nRemoved" : 0,
38+
"upserted" : [ ]
39+
})
40+
```
41+
42+
Look at 10 documents:
43+
44+
```
45+
> db.purchases.find().limit(10)
46+
{ "_id" : ObjectId("5cb1a49d3e0a85b364fc4aff"), "transaction" : "tx_0", "transaction_price" : 412, "transaction_type" : "credit card", "store_name" : "edgards" }
47+
{ "_id" : ObjectId("5cb1a49d3e0a85b364fc4b00"), "transaction" : "tx_1", "transaction_price" : 738, "transaction_type" : "credit card", "store_name" : "edgards" }
48+
{ "_id" : ObjectId("5cb1a49d3e0a85b364fc4b01"), "transaction" : "tx_2", "transaction_price" : 925, "transaction_type" : "cash", "store_name" : "edgards" }
49+
{ "_id" : ObjectId("5cb1a49d3e0a85b364fc4b02"), "transaction" : "tx_3", "transaction_price" : 509, "transaction_type" : "cash", "store_name" : "cna" }
50+
{ "_id" : ObjectId("5cb1a49d3e0a85b364fc4b03"), "transaction" : "tx_4", "transaction_price" : 380, "transaction_type" : "account", "store_name" : "picknpay" }
51+
{ "_id" : ObjectId("5cb1a49d3e0a85b364fc4b04"), "transaction" : "tx_5", "transaction_price" : 158, "transaction_type" : "credit card", "store_name" : "cna" }
52+
{ "_id" : ObjectId("5cb1a49d3e0a85b364fc4b05"), "transaction" : "tx_6", "transaction_price" : 342, "transaction_type" : "cash", "store_name" : "edgards" }
53+
{ "_id" : ObjectId("5cb1a49d3e0a85b364fc4b06"), "transaction" : "tx_7", "transaction_price" : 832, "transaction_type" : "credit card", "store_name" : "picknpay" }
54+
{ "_id" : ObjectId("5cb1a49d3e0a85b364fc4b07"), "transaction" : "tx_8", "transaction_price" : 841, "transaction_type" : "cash", "store_name" : "picknpay" }
55+
{ "_id" : ObjectId("5cb1a49d3e0a85b364fc4b08"), "transaction" : "tx_9", "transaction_price" : 263, "transaction_type" : "cash", "store_name" : "checkers" }
56+
```

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /