天道酬勤,学无止境

mongodb

Spring java MongoDB @Query annotation for order top or first records

I use @Query annotation and crudRepository to fetch data from MongoDB. Example: @Query("{$query: id: ?0}, $orderby: {dateTime: -1}}") public List<A> findId( Integer id, Pageable pageable ); What do I need to add to my @Query notation if i want to fetch only first N records of collection, or only top N records of collection? I would like to use dynamic query and dynamic set limit and order (first or top records).

2022-01-19 01:11:07    分类:问答    java   spring   mongodb

Access MongoDB from Java [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 8 years ago. I'm trying out MongoDB, and I wondering what the best way of mapping data from MongoDB to Java is. My use case is that I'm trying to store 100.000+ documents (say movie+actors information), and I want to store text and image data (small images, around 100kb-300kb) I've tried Morphia, but it seems to be quite dead

2022-01-19 01:00:44    分类:问答    java   mongodb

can't serialize class in MongoDB Java and String are encoded

My simple application is suppose to just populate MongoDB with a mapping between _id to user. My key (_id) is in JSON format and its value is just a long. { "_id": { "a": "1B2ac", "b": "Windows NT 5.2; WOW64; rv:16.0 Ff/6.0" }, "user": 1999129 } I have a couple of issues: Issue 1: I get can's serialize class... when I try to insert: Caused by: java.lang.IllegalArgumentException: can't serialize class test.mongo.foo.DummyObject at org.bson.BSONEncoder._putObjectField(BSONEncoder.java:234) at org.bson.BSONEncoder.putObject(BSONEncoder.java:121) at org.bson.BSONEncoder.putObject(BSONEncoder.java

2022-01-19 00:32:42    分类:问答    java   json   mongodb

importing CSV file MongoDB with ISODate

When I export my data from mongoDB I obtain the following file: Everything is a string in the mongoDB except for the date that is ISODate. 123@123.com,sha1:64000:18:BTJnM903gIt5FNlSsZIRx1tLC9ErPJuB:9YVs800sgRPr1aaLj73qqnJ6,123,123,123@123.com,2017-04-28T09:20:07.480Z,cus_AYcVXIUf68nT52 If I import this file into MongoDB it import each value as String value. I need to parse the date as Date format, the rest can be string. I've seen that there's an argument for MongoImport --columnsHaveTypes. I've tryed it without any result: mongoimport -u test-p test --authenticationDatabase test -h localhost

2022-01-18 23:16:46    分类:问答    mongodb   date   mongoimport   isodate

How to retrieve distinct keys inside an object in MongoDB

I have this in MongoDB: { "_id" : ObjectId("58fb35531eb5df245d5d434f"), "name" : "d1.html", "indexation" : { "Citroen" : 1, "color" : 1, "Marca" : 1, "rojo" : 1 } } { "_id" : ObjectId("58fb35531eb5df245d5d4350"), "name" : "d2.html", "indexation" : { "blancos" : 1, "ocasión" : 1, "Madrid" : 1, "Coches" : 1, "rojo" : 1, "coches" : 1 } } { "_id" : ObjectId("58fb35531eb5df245d5d4351"), "name" : "d3.html", "indexation" : { "rojos" : 1, "Ocasión" : 1, "marcas" : 1, "Madrid" : 1, "blancas" : 1, "autos" : 1, "de" : 1 } } You can see an image containing the above: And I would like to get the distinct

2022-01-18 18:39:01    分类:问答    arrays   mongodb   mongodb-query

Using aggregate $lookup and $mergeObjects

I want to join collection. before, I used only lookup, so that I could get separated field that is joined. but I need to get result similar mysql join. I noticed there is $lookup and $mergeObjects for this action but not working well. user collection model. { "_id": ObjectId("xxxxxxx"), //this is default id from mongoDB "name": 'admin user', "email": 'admin@test.com', "password": 'xxxxxxxx', "roles": [ { "id": 0, "approved": true },{ "id": 2, "approved": true } ] },{ "_id": ObjectId("xxxxxxx"), //this is default id from mongoDB "name": 'userOne', "email": 'user@test.com', "password": 'xxxxxxxx

2022-01-18 18:29:12    分类:问答    javascript   node.js   mongodb   mongodb-query   aggregation-framework

MongoDB - Query by sub-tree

I have a document structure that the same as the simplified version shown below: { some_other_props: { ... }, systems: { sys1: { score: 24, metric: 52 }, another_sys: { score: 9, metric: 77 }, some_other_sys: { score: 12, metric: 5 } } } I'd like to return all the documents where score : { "$gte" : 15 } is true for any of the sub-documents. The only way I could think of doing this was to get the list of keys in system and concat that into some kind of or-statement mess. But it seems like I'm doing something wrong. I could reformat the document structure so that each system is in its own

2022-01-18 18:13:04    分类:问答    mongodb

Linking errors when building c++ project using mongo-cxx-driver

I am currently developing a C++ application which requires the use of the mongo-cxx-driver for accessing a MongoDB instance. I attempted a couple of methods of installation, and am met with the same linker issues each time. Initially, I attempted to install mongo-cxx-drivers and mongod-c-driver as detailed here: https://mongodb.github.io/mongo-cxx-driver/mongocxx-v3/installation/ Using the following portion of my CMake configuration, I was able to get auto-completion working and my IDE to recognize the libraries: . . . set(CMAKE_CXX_STANDARD 17) set(BUILD_DIR "cmake-build-debug") set(BUILD

2022-01-18 17:51:58    分类:问答    c++   mongodb   mongo-cxx-driver

How do I sort a collection based on values in an array

I have collection named result with following values:- > db.result.findOne() { "_id" : ObjectId("53b05264421aa97e980ba404"), "result" : [ { "attempted" : 49, "subject_total_marks" : 50, "score" : 15, "correct_subject_answer" : 15, "subject" : "Biology" }, { "attempted" : 30, "subject_total_marks" : 30, "score" : 4, "correct_subject_answer" : 4, "subject" : "Chemistry" }, { "attempted" : 20, "subject_total_marks" : 20, "score" : 7, "correct_subject_answer" : 7, "subject" : "Physics" }, { "attempted" : 99, "correct_subject_answer" : 26, "score" : 26, "subject_total_marks" : 100, "subject" :

2022-01-18 17:03:05    分类:问答    python   mongodb   sorting   mongodb-query   aggregation-framework

How to display arbitrary, schemaless data in HTML with node.js / mongodb

I'm using mongodb to store application error logs as json documents. I want to be able to format the error logs as HTML rather than returning the plain json to the browser. The logs are properly schemaless - they could change at any time, so it's no use trying to do this (in Jade): - var items = jsonResults - each item in items h3 Server alias: #{item.ServerAlias} p UUID: #{item.UUID} p Stack trace: #{item.StackTrace} h3 Session: #{item.Session} p URL token: #{item.Session.UrlToken} p Session messages: #{item.Session.SessionMessages} as I don't know what's actually going to be in the JSON

2022-01-18 16:12:08    分类:问答    node.js   mongodb   express   pug   mongoskin