mongodb

How do i register AbstractMongoEventListener programmatically?

北慕城南 提交于 2021-02-07 10:50:22
问题 In my Spring Boot application, i have a configuration, which reads entries from a Mongo database. After this is done, my subclass of AbstractMongoEventListener is created, even though it operates on a different table and different scope (my own custom @CustomerScope ). Here is the listener: @CustomerScoped @Component public class ProjectsRepositoryListener extends AbstractMongoEventListener<Project> { @Override public void onAfterSave(Project source, DBObject dbo) { System.out.println("saved"

Find Distinct Embedded Document and further make distinct using Field

扶醉桌前 提交于 2021-02-07 10:34:43
问题 I'm using Spring Boot Mongo example. I went through many links like: I want result with distinct value of one field from mongodb using spring data, but still did not get any break through. I am using below code: List<Object> obj = mongoTemplate.query(Health.class).distinct("healths").all(); List<Health> healths = null; if (!CollectionUtils.isEmpty(obj)) { healths = obj.stream().map(e -> (Health) e).collect(Collectors.toList()); } With this code I am getting duplicate HealthCode=E , Is there

Why does ISO date in Mongodb display one day earlier?

荒凉一梦 提交于 2021-02-07 10:32:23
问题 The stored date looks like this: ... "date_of_birth" : ISODate("1920-01-02T00:00:00Z"), ... Using moment, it is formatted in the model (in order to populate the input for updating the document) like this: AuthorSchema .virtual('date_of_birth_update_format') .get(function(){ // format in JavaScript date format (YYYY-MM-DD) to display in input type="date" return this.date_of_birth ? moment(this.date_of_birth).format('YYYY-MM-DD') : ''; }); Retrieved from the collection and displayed, it

React POST requests with Express/Node and MongoDB

允我心安 提交于 2021-02-07 10:29:59
问题 I'm writing program that uses React as front-end, and an Express/Node API for the backend which then does CRUD operations in a MongoDB database. Right now, I'm using the native JS fetch() API to perform GET/POST operations on my front end. The GET requests work just fine, but my POST requests seem to not be working. On my front end, I have a form and a handler for form submission like so: handleSubmit(){ let databody = { "name": this.state.nameIn, "quote": this.state.quoteIn } return fetch(

Opening a port on Ubuntu

元气小坏坏 提交于 2021-02-07 10:21:02
问题 I am trying to open up port on my Ubuntu machine to allow me to connect the Mongo using an external program. I ran this which is the command line to open a new port: sudo iptables -A INPUT -p tcp --dport 27017 -j ACCEPT but when I ran this to check if the new rule was there... sudo netstat -ntlp | grep LISTEN ...the new port wasn't in the list - any ideas? 回答1: I think the mangodb instance was not started, apart from that , sudo netstat -ntlp | grep LISTEN gives the list ports that are active

Opening a port on Ubuntu

跟風遠走 提交于 2021-02-07 10:19:56
问题 I am trying to open up port on my Ubuntu machine to allow me to connect the Mongo using an external program. I ran this which is the command line to open a new port: sudo iptables -A INPUT -p tcp --dport 27017 -j ACCEPT but when I ran this to check if the new rule was there... sudo netstat -ntlp | grep LISTEN ...the new port wasn't in the list - any ideas? 回答1: I think the mangodb instance was not started, apart from that , sudo netstat -ntlp | grep LISTEN gives the list ports that are active

Querying same document in parallel in the same API in mongoDB

可紊 提交于 2021-02-07 09:40:05
问题 I have a an API written in typescript and I try to run parallel queries for same document by using promise.allsettled however it performs worse and I guess they run sequentially. Is there a way to perform parallel queries on the same document in the same connection for mongoDB. here is the code: console.time("normal"); let normal = await ContentRepo.geBySkillIdWithSourceFiltered( [chosenSkillsArr[0].sid!], readContentIds, body.isVideoIncluded, true, true ); console.timeEnd("normal"); console

Querying same document in parallel in the same API in mongoDB

泪湿孤枕 提交于 2021-02-07 09:39:34
问题 I have a an API written in typescript and I try to run parallel queries for same document by using promise.allsettled however it performs worse and I guess they run sequentially. Is there a way to perform parallel queries on the same document in the same connection for mongoDB. here is the code: console.time("normal"); let normal = await ContentRepo.geBySkillIdWithSourceFiltered( [chosenSkillsArr[0].sid!], readContentIds, body.isVideoIncluded, true, true ); console.timeEnd("normal"); console

How to make embedded mongodb keep the data on application shutdown?

孤人 提交于 2021-02-07 09:33:43
问题 I don't want to install the full mongodb, so I created a simple spring-boot application with the following pom: <!-- This dependency is to have an embedded mongodb --> <dependency> <groupId>de.flapdoodle.embed</groupId> <artifactId>de.flapdoodle.embed.mongo</artifactId> <version>1.50.5</version> </dependency> <!-- while this provides a spring factory bean for the embedded mongodb --> <dependency> <groupId>cz.jirutka.spring</groupId> <artifactId>embedmongo-spring</artifactId> <version>RELEASE<

Mongo find value with unknown parent key

徘徊边缘 提交于 2021-02-07 09:24:29
问题 I am looking for a value in a Mongo table where its parent key might not have a descriptive or known name. Here is an example of what one of our documents looks like. { "assetsId": { "0": "546cf2f8585ffa451bb68369" }, "slotTypes": { "0": { "usage": "json" }, "1": { "usage": "image" } } } I am looking to see if this contains "usage": "json" in slotTypes, but I can't guarantee that the parent key for this usage will be "0". I tried using the following query without any luck: db.documents.find(