mongodb

docker-compose mongo unable to authenticate after initialising with custom admin password

China☆狼群 提交于 2021-02-11 12:27:36
问题 This is my docker-compose file docker-compose.yml version: "3.1" services: mongo1: container_name: mongo1 image: mongo restart: always environment: MONGO_INITDB_ROOT_USERNAME: ${MONGO_USER} MONGO_INITDB_ROOT_PASSWORD: ${MONGO_PASS} MONGO_INITDB_DATABASE: ${MONGO_DB_NAME} ports: - 27017:27017 - 28017:28017 env_file: - .env volumes: - volume-mongo:/data/db - ./mongo/init-mongo-js.sh:/docker-entrypoint-initdb.d/init-mongo.sh:ro command: ['--auth', '--wiredTigerCacheSizeGB=1'] networks: - mongo

Embedded MongoDb not picked up for Application test

a 夏天 提交于 2021-02-11 12:24:41
问题 Application test AuthServiceApplicationTests.class is trying to run against local MongoDb instance which was setup for development and running behind the process. I shutdown this instance, and expected that it will run against embedded mongoDb with de.flapdoodle.embed.mongo . <!-- Integration Tests --> <dependency> <groupId>de.flapdoodle.embed</groupId> <artifactId>de.flapdoodle.embed.mongo</artifactId> <version>2.2.0</version> <scope>test</scope> </dependency> <!--/ Integration Tests -->

Export text stored as Bindata in mongodb

风流意气都作罢 提交于 2021-02-11 12:12:31
问题 I have a quite big collection of data, made by third parties, it contains a Bindata "package" column where plain ASCII is actually stored. I mean, they could have stored the text as string. I have to export this collection in csv format, which works quite well with mongoexport, but the output contains the base64 encoded values for the "package" column. I need the actual text from that column, not BinData(0,\"NDYuN.....==") . What I've tried so far is update the collection with a new column

Retrieving Images stored in Mongodb with Nodejs

雨燕双飞 提交于 2021-02-11 11:59:25
问题 I have small thumbnails stored in a MongoDB collection. While I can extract them with a .findOne() I can not serve them back over an ExpressJS route correctly. I am not storing thumbs on disk as the heroku environment does not guarantee persisted storage. I am not using GridFS as these are thumbs < 16MB. Inserting a a new document into the collection goes something like this: MongoClient.connect(url, function(err, db){ var newImg = fs.readFileSync(req.file.path); var encImg = newImg.toString(

Retrieving Images stored in Mongodb with Nodejs

十年热恋 提交于 2021-02-11 11:52:45
问题 I have small thumbnails stored in a MongoDB collection. While I can extract them with a .findOne() I can not serve them back over an ExpressJS route correctly. I am not storing thumbs on disk as the heroku environment does not guarantee persisted storage. I am not using GridFS as these are thumbs < 16MB. Inserting a a new document into the collection goes something like this: MongoClient.connect(url, function(err, db){ var newImg = fs.readFileSync(req.file.path); var encImg = newImg.toString(

How to change elements of an array field to values of a dict with a single attribute in MongoDB

寵の児 提交于 2021-02-11 09:12:23
问题 I need a way to change the elements of an array field to values of a dict with a single attribute. I don't have to write the result back into my table. I just have to read it that way. My table has rows like this : {a: 1, b:[ {...}, ..., {...} ], c: 2} I need a query that returns each row rewritten like this : {a: 1, b: [ {foo: { ... }}, ..., {foo: {...}} ], c: 2} In other words, each element of b becomes a dict with a single attribute, foo . This feels like a job for $project or $replaceRoot

How to change elements of an array field to values of a dict with a single attribute in MongoDB

荒凉一梦 提交于 2021-02-11 09:11:09
问题 I need a way to change the elements of an array field to values of a dict with a single attribute. I don't have to write the result back into my table. I just have to read it that way. My table has rows like this : {a: 1, b:[ {...}, ..., {...} ], c: 2} I need a query that returns each row rewritten like this : {a: 1, b: [ {foo: { ... }}, ..., {foo: {...}} ], c: 2} In other words, each element of b becomes a dict with a single attribute, foo . This feels like a job for $project or $replaceRoot

How to change elements of an array field to values of a dict with a single attribute in MongoDB

落爺英雄遲暮 提交于 2021-02-11 09:10:26
问题 I need a way to change the elements of an array field to values of a dict with a single attribute. I don't have to write the result back into my table. I just have to read it that way. My table has rows like this : {a: 1, b:[ {...}, ..., {...} ], c: 2} I need a query that returns each row rewritten like this : {a: 1, b: [ {foo: { ... }}, ..., {foo: {...}} ], c: 2} In other words, each element of b becomes a dict with a single attribute, foo . This feels like a job for $project or $replaceRoot

How to apply group by on multiple nested document in MongoDB using MongoTemplate

自古美人都是妖i 提交于 2021-02-11 08:49:31
问题 db.students.aggregate([ { $unwind: "$details" }, { $group: { _id: { sid: "$details.student._id", statuscode: "$details.studentStatus.statusCode" }, total: { $sum: 1 } } } ]); The query is working fine and need to convert into mongo template . Sample document: { "_id" : 59, "details" : [ { "student" : { "_id" : "5d3145a8523a2e602e5e0200" }, "studentStatus" : { "statusCode" : 1 } } ] } 回答1: The Spring Data MongoTemplate code for the given aggregation is as follows. Note that I have added a

Exception while connecting through Spring Data to MongoDB

随声附和 提交于 2021-02-11 08:10:37
问题 I am working on some test program for SpringData MongoDB , I have done it same as it's mentioned on http://static.springsource.org/spring-data/data-document/docs/1.0.0.M2/reference/html/#mongo.core. But it's showing exceptions: package com.springMongo.core; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org