mongodb

Specify MongoDb collection name at runtime in Spring boot

雨燕双飞 提交于 2021-02-07 20:13:47
问题 I am trying to reuse my existing EmployeeRepository code (see below) in two different microservices to store data in two different collections (in the same database). @Document(collection = "employee") public interface EmployeeRepository extends MongoRepository<Employee, String> Is it possible to modify @Document(collection = "employee") to accept runtime parameters? For e.g. something like @Document(collection = ${COLLECTION_NAME}) . Would you recommend this approach or should I create a new

MongoDB connection to MongoLab timing out in NodeJS on Heroku

霸气de小男生 提交于 2021-02-07 19:50:44
问题 At first everything works, and I can successfully store data by posting to the /upload route. But after 120 seconds of inactivity, the timeout event fires, and future attempts to store data fail. However the callback isn't called, so there is no "Unable to insert..." message at the log. var express = require('express'); var bodyParser = require('body-parser'); var winston = require('winston'); var config = require('./config'); var MongoClient = require('mongodb').MongoClient; var app =

MongoDB connection to MongoLab timing out in NodeJS on Heroku

独自空忆成欢 提交于 2021-02-07 19:47:29
问题 At first everything works, and I can successfully store data by posting to the /upload route. But after 120 seconds of inactivity, the timeout event fires, and future attempts to store data fail. However the callback isn't called, so there is no "Unable to insert..." message at the log. var express = require('express'); var bodyParser = require('body-parser'); var winston = require('winston'); var config = require('./config'); var MongoClient = require('mongodb').MongoClient; var app =

Error Message from MongoDB “Operation `disneys.insertOne()` buffering timed out after 10000ms”"

╄→гoц情女王★ 提交于 2021-02-07 19:36:19
问题 I'm currently creating a new API with MongoDB and Express, and I'm currently having this issue "Operation disneys.insertOne() buffering timed out after 10000ms." I'm currently using route.rest to test my API. However, I don't know what I'm currently doing wrong, could someone take a look at my Github Repository ? This is the way that I setup my API calls: const express = require("express"); const router = express.Router(); const Disney = require("../models/disneyCharacter"); // Getting all

Error Message from MongoDB “Operation `disneys.insertOne()` buffering timed out after 10000ms”"

时光总嘲笑我的痴心妄想 提交于 2021-02-07 19:36:00
问题 I'm currently creating a new API with MongoDB and Express, and I'm currently having this issue "Operation disneys.insertOne() buffering timed out after 10000ms." I'm currently using route.rest to test my API. However, I don't know what I'm currently doing wrong, could someone take a look at my Github Repository ? This is the way that I setup my API calls: const express = require("express"); const router = express.Router(); const Disney = require("../models/disneyCharacter"); // Getting all

MongoDB : Remove last two characters from String

删除回忆录丶 提交于 2021-02-07 19:14:06
问题 How to remove the last two characters of String in MongoDB? I have tried below solution but it did not work. $substr: [ "$document.field", 0, { $strLenCP: "$document.field" } - 2 ] 回答1: You have to use $add or $subrtract to evaluate the length of a new string: db.collection.aggregate([ { $project: { newStr: { $substr: [ "$document.field", 0, { $add: [ { $strLenCP: "$document.field" }, -2 ] } ] } } } ]) MongoDB Playground 来源: https://stackoverflow.com/questions/56537076/mongodb-remove-last-two

MongoDB - Java Driver performance

牧云@^-^@ 提交于 2021-02-07 18:30:09
问题 This is my environments. Java - 1.7 by Oracle mongod v2.4.5 (in Mongolab) I found difference in performance of the two MongoDB driver(2.9.3 vs 2.11.2) When I run same code using each driver, 2.11.2 slower than 2.9.3. for(int i=0; i<1000; i++){ BasicDBObject doc = new BasicDBObject( "currentTime", new SimpleDateFormat("HH:mm:ss:SSS").format(Calendar.getInstance().getTime()) ); coll.insert(doc); } DBCursor cursor = coll.find(); try{ while(cursor.hasNext()){ System.out.println(cursor.next()); }

MongoDB: export distinct column value

余生颓废 提交于 2021-02-07 18:22:32
问题 Anyone have idea how to export distinct column value on mongodb using mongoexport command. Command: db.coll.distinct("uid"); The solution i have tried is : mongoexport --csv -d db -c collection -q '{distinct: "collection", "key": "uid"}' -f "uid" -o distinctUid.csv 回答1: It's not possible to do it this way. distinct is a database command, and --query option allows to use only a query to filter documents. If you are using mongodb v3.4 or later, you can use views to aggregate your collection and

MongoDB: export distinct column value

我与影子孤独终老i 提交于 2021-02-07 18:22:14
问题 Anyone have idea how to export distinct column value on mongodb using mongoexport command. Command: db.coll.distinct("uid"); The solution i have tried is : mongoexport --csv -d db -c collection -q '{distinct: "collection", "key": "uid"}' -f "uid" -o distinctUid.csv 回答1: It's not possible to do it this way. distinct is a database command, and --query option allows to use only a query to filter documents. If you are using mongodb v3.4 or later, you can use views to aggregate your collection and

MongoDB: export distinct column value

眉间皱痕 提交于 2021-02-07 18:22:02
问题 Anyone have idea how to export distinct column value on mongodb using mongoexport command. Command: db.coll.distinct("uid"); The solution i have tried is : mongoexport --csv -d db -c collection -q '{distinct: "collection", "key": "uid"}' -f "uid" -o distinctUid.csv 回答1: It's not possible to do it this way. distinct is a database command, and --query option allows to use only a query to filter documents. If you are using mongodb v3.4 or later, you can use views to aggregate your collection and