Posts

Showing posts with the label mongodb

How to add the mongoDB driver and connector to the jupyter notebook?

How to add the mongoDB driver and connector to the jupyter notebook? I would like to add the MongoDB Spark Connector v2.2 to the Jupyter notebook to pull data as dataframes from a mongodb database. However I keep on getting that error, I am not sure how to proceed from here. MongoDB Spark Connector v2.2 An error occurred while calling o40.load. : java.lang.NoClassDefFoundError: com/mongodb/ConnectionString The Spark version I am using is 2.3.1 2.3.1 The Python version I am using is 3.6.5 |Anaconda, Inc.| 3.6.5 |Anaconda, Inc.| I am running the Jupyter notebook on Windows 10 Windows 10 I downloaded the .jar files from the following link, specifically Version: 2.2.3-s_2.11 2.2.3-s_2.11 How to add the mongoDB driver and connector to the jupyter notebook ? I am not quite sure how to point the jupyter notebook to the correct location in windows 10 The code is as follows import findspark findspark.init() import os %env os.environ['PYSPARK_SUBMIT_ARGS'] = '--packages org.mongod...

Extracting data from a complex MongoDB database using PyMongo and converting it to a .csv file

Extracting data from a complex MongoDB database using PyMongo and converting it to a .csv file I have a complex MongoDB database, consisting of documents nested upto 7 levels deep. I need to use PyMongo to extract the data, and then convert the extracted data to a .csv file. What have you tried so far? – Adam Smith Jul 2 at 4:08 Can you use mongoexport? – Astro Jul 2 at 4:11 So far I am able to extract the entire database and store it as a Python object. I am then able to convert this object to a .csv file. However the .csv file has thousands of columns. I need to know how I can extract the data in a clean manner. – pack24 Jul 2 at ...

How to wrap bulk upsert in Mongo with Task in C#

How to wrap bulk upsert in Mongo with Task in C# I have some model public partial class Option { [BsonId] public int Id { get; set; } public Quote Quote { get; set; } public Contract Contract { get; set; } } Method that does bulk write public Task SaveOptions(List<Option> contracts) { var context = new MongoContext(); var processes = new List<Task<UpdateResult>>(); var collection = context.Storage.GetCollection<Option>("options"); contracts.ForEach(contract => { var item = Builders<Option>.Update.Set(o => o, contract); var options = new UpdateOptions { IsUpsert = true }; processes.Add(collection.UpdateOneAsync(o => o.Id == contract.Id, item, options)); }); return Task.WhenAll(processes); } Call for the method above Task.WhenAll(service.SaveOptions(contracts)) // also tried without Task.WhenAll For some reason, it doesn't create any record in Mongo DB Update Tried to rewrite bulk write this way, still...

Authentication Fail with MongoDB Compass Community

Authentication Fail with MongoDB Compass Community I've just created a new MongoDB account and I'm now trying to connect the free cluster I created via MongoDB Compass Community application but I'm getting a 'Authentication Fail' error being displayed. This is what I've checked so far: From my MongoDB Clusters section when I clicked on the Connect (…) button which then gives you various options. From there, I selected 'Connect with MongoDB Compass' and copied the connection string. This was detected as expected by the Compass and the information was filled automatically in all the relevant fields and I also filled the password by copy/pasting it into the relevant field. 100% sure it is correct. I checked that the username used was indeed set up as an admin and it is. I checked my Authentication database was correct and it is. I've checked that my public IP was added to the whitelist and it is. The only thing I've noticed is that when I added my p...

node-fibers : yielding data out of a Fiber

node-fibers : yielding data out of a Fiber I just started working with node-fibers to actually try out something I had in mind to make it easier to make mongoose queries a little more easy to deal with. Unfortunately , I don't seem to understand what I'm doing wrong to get the users returned using the yield() to the main function that called Fiber. users yield() var Fiber = require("fibers"); var mongoose = require("mongoose"); var User = require('./user'); mongoose.connect('mongodb://localhost/fibers'); function wrapper() { let f = Fiber(function(){ var results; var fiber = Fiber.current; User.find({},function(err,users){ var results = Fiber(function(){ fiber.run(users); }).run(); }) results = Fiber.yield(); Fiber.yield(results); }); return f.run.bind(f); } var result = wrapper()(); console.log(result); use sync in...

GraphQL Schema for mongoose Mixed type (Schema.Types.Mixed)

GraphQL Schema for mongoose Mixed type (Schema.Types.Mixed) I have a Mongoose schema with the following structure: import mongoose from 'mongoose'; const PropertySchema = new mongoose.Schema({ name: { type: String }, description: { type: String }, value: { type: mongoose.Schema.Types.Mixed }, unit: { type: String }, }); export default mongoose.model('Property', PropertySchema); I need to build a GraphQL query for the given data. How do I handle the Mixed type for the value property ? value Here is my try: import NodeInterface from '../interfaces'; import PropertyModel from '../../models/Property'; const fields = { id: { type: new GraphQLNonNull(GraphQLID), resolve: (obj) => dbIdToNodeId(obj._id, "Property") }, name: { type: GraphQLString }, description: { type: GraphQLString }, value: { type: <<< What ...

Proper Mongoose Subdocument Relation

Proper Mongoose Subdocument Relation I have a model const userSchema = Schema({ username: String }) const invitationSchema = Schema({ decision: String, user: { type: Schema.ObjectId, ref: 'User' } }) const groupSchema = Schema({ name: String, invitations: [{ type: Schema.ObjectId, ref: 'Invitation' }] }) So the basic model looks like group { name invitations [ user { username } ] } As user i would like to get all groups that i have invitations for const user = getContextUser() Group.find({ 'invitations.user': user._id }) But it doesn't seem to work, i could use a property group referring to Group schema in Invitation model, but i want the good way approach Group Invitation How to i get all groups that user have invitations for Don't look at this below, this is my actual model representation in json, just in case // GROUP { "_id": ObjectId("5b3901dd9a8c0e6790af4ee8"), "i...

How compare date in spring mongo

How compare date in spring mongo I want to fetch result bw two date in Mongo and spring but it show parse exception. If I pass like date as string then no result. How compare date in spring and Mongo application. Aggregation.match(Criteria.where("date").gte(new Date("2018-06-24")).lte(new Date("2018-06-30"))); My collection: { "_id" : ObjectId("5b34a31a68f1b041aa13b82f"), "date" : ISODate("2018-06-28T00:00:00Z"), "eventname" : "app open" } 1 Answer 1 You can try something like: DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); Date startDate = df.parse("2018-06-24"); Date endDate = df.parse("2018-06-30"); Aggregation.match(Criteria.where("date").gte(startDate).lte(endDate)); Please see also Spring Data MongoDB Date Between and Spring data mongodb search for ...

Retrieving User Collection from API / MongoDB but exclude Password Field?

Retrieving User Collection from API / MongoDB but exclude Password Field? I am constructing an api which retrieves articles. I also have users in my database, and would like to have one endpoint which returns the user. /api/users/:userid . This returns something along these lines: /api/users/:userid { "articles": , //array w. references to articles the user has written "_id": "5b1321321bcda0e3364251d7e4a", "email": "user@email.com", "password": "$2a$1231241gi14k41k42bk12bh3k127iP/k1LAqwPdbgF/bXXpRia", "__v": 0 } -- However, I am not sure whether it's a good idea to return the (encrypted) password in the API. Can I somehow exclude this field, or would you recommend to store emails + user_ids in a separate collection on mongodb, or how are things like this usually handled? 2 Answers 2 you can use Project Fields to Retu...