Meteor get Files via GridFS of a Remote Collection - mongodb

I am connecting to some remote collections via the following pattern:
let remoteDB = new MongoInternals.RemoteCollectionDriver("mongodb://localhost:7071/meteor");
export const RemoteCollection = new Mongo.Collection("remoteCollection", {_driver:remoteDB});
Which is working fine for normal collections.
However, there is a FilesCollection (via ostrio:files) that also exists in this remote DB.
The FileCollection constructor does not let me pass the _driver options, so I am asking if someone has managed to load the remote files via gridfs, before opening a ticket on the project.

Looking at the source of Meteor-Files, the Mongo.Collection is added in lines 126-130 of server.js and lines 73-77 of client.js without any options being passed in.
What you can do is pass your own RemoteCollection into the FilesCollection constructor and the collection will use your collection and it's remote.
let remoteDB = new MongoInternals.RemoteCollectionDriver("mongodb://localhost:7071/meteor");
export const RemoteCollection = new Mongo.Collection("remoteCollection", {_driver:remoteDB});
export const RemoteFilesCollection = new FilesCollection({
collectionName: "remoteCollection",
collection: RemoteCollection
});
You'll also need to add all the extra code for GridFS integration to Meteor-Files: https://github.com/VeliovGroup/Meteor-Files/wiki/GridFS-Integration

Related

Fetching data from mongo-tracker in ' Rasa' and storing it in mongoDB at runtime like sender_id,timestamp

Could you please tell me how are you fetching specific details from the tracker store. Elaborating my doubt below:
in my run_app.py (socketIO class) i have used mongotracker like this-
db = MongoTrackerStore(domain=“d.yml”,host=‘host ip’, db=‘xyz’, username=“x”,password=“x”,collection=“x”,event_broker=None)
agent = Agent.load(‘models/dialogue’, interpreter=‘models/current/nlu’,action_endpoint = action_endpoint,tracker_store=db)
now i want to fetch some data like db.sender_id or db.event. the reason of doing it is to store it column wise on my mongodb.Please help me solving this problem.
This information should already be stored in your mongodb, so there should be no extra need for you to store it.
Maybe see the documentation for this https://rasa.com/docs/core/tracker_stores/ and make sure your endpoints.yml file includes the correct information:
tracker_store:
store_type: mongod
url: <url to your mongo instance, e.g. mongodb://localhost:27017>
db: <name of the db within your mongo instance, e.g. rasa>
username: <username used for authentication>
password: <password used for authentication>
auth_source: <database name associated with the user’s credentials>
For information on how to fetch specific details from your mongodb maybe have a look at the mongodb docs https://docs.mongodb.com/manual/reference/method/db.collection.find/.
look at this Example
I am using Pymongo to connect monogoDB. try to understand my code
from typing import Any, Text, Dict, List
from pymongo.database import Database
from pymongo import MongoClient
from rasa_sdk import Action, Tracker
from rasa_sdk.executor import CollectingDispatcher
import pymongo
# url="http://localhost:3000/api"
client = pymongo.MongoClient("localhost", 27017)
db=client.sample
class mercdesCarAction(Action):
def name(self):
return "mercdesCarAction"
def run(self,dispatcher,tracker,domain):
res = db.datas.find({'action':'mercdesCarAction'})
for i in res:
dispatcher.utter_button_message(i['text'],i['buttons'])
return []

ReactJS / MongoDB: export const Database (how to insert.before)?

I am using MeteorJS as my framework.
In my imports/api/collections/categories.js file, I have:
export const Photos = new Mongo.Collection('photos');
On the server side, I have:
Photos = new Mongo.Collection('photos');
How can I insert.before so all my documents have an extra field when they get added to the database?
Before I was exporting for React, I had:
Photos = new Mongo.Collection('photos');
Photos.before.insert(function(userId,doc){
doc.createdAt=Date.now();doc.status=0;
});
But that doesn't work with:
export const Photos...
Ideas how I achieve the insert before?
Okay, as it turns out, I can do what I did before:
Photos.before.insert(function(userId,doc){doc.status=0;});
I just had to bring in this package into Meteor:
matb33:collection-hooks

WebStorm 11 unrecognized MongoDb (with mongoose) functions

WebStorm gives me a warning of "Unrecognized function or method" on functions like:
Schema.find() [find() not recognized]
Schema.aggregate() [aggregate() not recognized]
Schema.findOneAndUpdate() [findOneAndUpdate() not recognized]
I've tried to Enabling the NodeJs core libraries and to install
mongodb-DefinitelyType
mongoose-DefinitelyType
mongoose-auto-increment-DefinitelyType
mongoose-deep-populate-DefinitelyType
mongoose-DefinitelyType
mongoose-mock-DefinitelyType
under Preferences > JavaScript > Libraries
But this has not solved my problem. Does someone knows a solution?
This issue is tracked as https://youtrack.jetbrains.com/issue/WEB-17099; please see https://youtrack.jetbrains.com/issue/WEB-17099#comment=27-1441265 for possible workaround
This is possible solution working for me without any issues.
Moving the relative path out of the require() statement as follows.
const PATH = '../models/';
const User = require(PATH + 'user');
Alternatively
Do not import Schema separately.
Just import mongoose like this
const mongoose = require('mongoose');
and use mongoose.Schema to access Schema
I don't know the reason but somehow this works:
export
module.exports.User = User; // your model
import
const User = require("../dbSchema/user.js").User;
Note that the schema is inserted correctly. Don't forget to check your Schema.
Sample
module.exports = mongoose.model('SampleCollection', SampleSchema);

RavenDB v3 persist Database Creation

My program does the following:
Creates a new EmbeddedDocument store
docStore = new DocumentStore
{
DefaultDatabase = "Default",
Url = url
};
docStore.Conventions.DefaultQueryingConsistency = ConsistencyOptions.QueryYourWrites;
docStore.Initialize();
Creates a new database within that document store
using (var session = docStore.OpenSession())
{
docStore.DatabaseCommands.GlobalAdmin.CreateDatabase(
new DatabaseDocument
{
Id = name,
Settings = settings
});
session.SaveChanges();
}
Starts up a smuggler process that imports data from a ravendump file into the newly created database.
When I navigate to localhost:port while step 2 and 3 are occuring, I see the database get created and the documents get put into the database.
Now, once that process spins down, and I attempt to reconnect to the embedded database, everything is gone--It's like the database creation and import never took place. What am I missing? Do I need to call Save on something?

iPhone - Connection String and DB File

I am developing a iPhone app using Monotouch. I need to access a Sqlite DB. In my soultion, I have a contracts, data access, business access and UI project. I have two questions:
Where should I keep my DB file? Originally, I put it in the data access project. When I compile my business access project it copies the DB file to the output, but when I compile my UI project it does not (UI has a reference to business access which has a ref to data access). I moved it to the UI project, but it feels wrong to keep it there.
Where should I keep the connection string to the DB? Is there a concept of config files?
Here is what we do:
We ship a copy of the DB in the application. It is included as Content, Always Copy in the project.
On the user's machine, it is stored in the special directory Environment.SpecialFolder.Personal.
When the app is started, we check to see if the database exists on the user's system and, if not, copy it there.
The connection string is just "Data Source=" + sDatabasePath.
Here is a sample of the code that we use for this (I hacked in the connection stuff since we use a homebuilt class for managing the DB, but you should get the idea):
const string DATABASE_FILE_NAME = "MyDB.db3";
bool fSuccess = false;
DbConnection conn = new DbConnection ();
string sApplicationDir = Path.Combine (Environment.GetFolderPath (Environment.SpecialFolder.Personal), "MyApplicationSubDir");
if (!Directory.Exists (sApplicationDir)) {
Directory.CreateDirectory (sApplicationDir);
}
// Generate the directory to the database file
string sDatabaseDir = Path.Combine (sApplicationDir, "Database");
m_sDatabaseDir = sDatabaseDir;
if (!Directory.Exists (sDatabaseDir)) {
Directory.CreateDirectory (sDatabaseDir);
}
// Generate the path to the database file
string sDatabasePath = Path.Combine (sDatabaseDir, DATABASE_FILE_NAME);
m_sDatabaseFile = sDatabasePath;
// If the file does not not exist
if (!File.Exists (sDatabasePath)) {
// Copy the base implementation
File.Copy (Path.Combine (Path.Combine (Environment.CurrentDirectory, "Database"), DATABASE_FILE_NAME), sDatabasePath);
}
// Initialize the DB
conn.ConnectionString = "Data Source=" + sDatabasePath;
out of interest, have you looked at sqlite-net ? http://code.google.com/p/sqlite-net/
Makes your DB handling a lot easier.