How to get DB resource knowing DB name? - intersystems-cache

I have database name.
I need to get db resource.
How? One option I see is to execute Config.Databases:List query and iterate over results till I find required name. After that open db by path and get the resource.

If you have only name of the database, you should before get a directory, because SYS.Database works only with directory path.
set dbName="TEST"
if ##Class(Config.Databases).Exists(dbName,.dbconfobj) {
Set dbObj=##class(SYS.Database).%OpenId(dbconfobj.Directory)
Set resourceName = dbObj.ResourceName
}
Database directory also you could get in this way
if ##Class(Config.Databases).Get("TEST1",.props) {
write $get(props("Directory"))
}
Or directory for default database for current namespace
set directory=$zu(12,"")

You can open database with Set dbObj=##class(SYS.Database).%OpenId("USER") and then get db resource as dbObj.ResourceName. SYS.Database docs and Config.Databases docs.

Related

Mongo shell keep passing document into default database "test". Eventhough I've already set to another database

I've set mongo database to current database using use currentdb.
When inserting data from local host. The data keeps entering into default database "test".
Running use <databasename> in the shell affects only the current session.
If you then connect with node.js/mongoose and use .save(), that will be a separate session.
To find out the database being used by a mongoose connection, check the name property.
To set the database name when connecting, specify the name in the URL like:
mongoose.connect('mongodb://user:pass#localhost:port/database');

GridFS throws Command listIndexes failed exception when uploading file

I am unable to get GridFS working on my computer. I am using .Net nuget MongoDb.Driver and I am trying to upload file to mongodb like this:
MongoClient client = new MongoDB.Driver.MongoClient();
IMongoDatabase dtb = client.GetDatabase("test");
GridFSBucket bucket = new GridFSBucket(dtb);
using (var stream = File.Open(#"<path>", FileMode.Open))
{
ObjectId id = bucket.UploadFromStream("data", stream);
var data = bucket.DownloadAsBytes(id);}
But if fails with exception: "MongoDB.Driver.MongoCommandException: Command listIndexes failed: ns does not exist: test.ts.files"
The same code works on other computer, fails on my computer. I even reinstalled the mongo with total cleanup. Weirdly the same function worked at first, then only for one specific database and after few tests nothing works.
I am sorry that I cannot provide any more information.
Most mongo operations will automatically create collections as needed, but some operations don't. The error message ns does not exist: test.ts.files implies that the namespace (database + collection) doesn't yet exist & needs to be created beforehand (presumably, that's why it's working on one computer but not another -- I bet if you looked at the test database on the working computer, you'd see that the ts.files collection exists, and I believe that different versions of mongo automatically create collections at slightly different times).
The grid fs spec says that when drivers first attempt to upload a file, they should first ensure that the appropriate indexes exist (that's the point at which this is erroring). Creating the necessary fs.files and fs.chunks collections manually should get this code working, but I'm a little surprised that the driver doesn't handle this for you.

Setting up journal path in mongod.conf?

I am using mongo v2.6 I am trying to setup path in mongod.conf but not sure what parameter name is called or whether mongo has one ? For instance for data, mongo uses this parameter: dbpath and for mongo logs, it uses this parameter: logpath
I am trying to find the parameter path name for journal ? The goal is to separate the journal logs from getting created in the data path & put them on separate volume.. is this doable ?
Thanks.
I don't believe there is a way of specifying the journal path in the config file, but there is a a fair workaround for this matter.
As mentioned in this DB StackExchange Topic, the person who provided the top answer recommends creating a symbolic link to a new mountpoint for the default journal folder, which is a sub-directory of the dbpath folder, named journal.

How to access the database imported through datapump

I just imported data dump through below command:
IMPDP user/pass FULL=Y DUMPFILE=BIRDV24012014.DMP LOGFILE=BIRDV24012014.log;
The dump has been restored the issue is i dont know how to connect to this database that i just imported, what service or TNS does it resides and how can i query it?
You didn't import a database, you imported the contents of your file into your existing database. If you could successfully run impdp user/pass then your ORACLE_SID etc. is already set and you should be able to log in and query with sqlplus user/pass.
If you've come from another RDBMS background you may be confusing 'database' with 'schema'. Depending on what was in the dump, you've probably created a load of schema objects and data under the USER schema or whatever your real 'user' value was).
The import makes no difference to this, but if you want to access the database from another client (e.g. from another machine, or over JDBC) then you'll need to check your listener configuration to get the hostname/IP address and port it's listening on, and get the service name for the database; all of which can be obtained from lsnrctl services if you have permission to run that. You can then use those values for a JDBC URL, or in a tnsnames.ora entry, or ODBC, etc.
Look at your ORACLE_SID environment variable. There you'll find the instance ID. If you ran the IMPDP tool as user Oracle, you should also be able to connect to the database using
sqlplus / as sysdba
If all fails, look at your /etc/oratab file to see which instances are available on this host.
On another note, your command seems incomplete. Datapump requires a DIRECTORYparameter to know where to look for the dumpfile you specified.

How do I specify a relative db path for storing mongodb's data?

I'd like to use a relative path for mongodb, so that each user has a separate data directory when running mongo.
I've tried setting
dbpath = ~/mongodb_data
in my config file, but for some reason that doesn't seem to work - I'm getting:
ERROR: dbpath (~/mongodb_data) does not exist.
At first I thought it might be a permissions error, but I'm running mongod under a user that has rw to ~/mongodb_data.
Is what I'm trying to do feasible, and, if so, how do I get to doing it?
Hello blueberryfields,
I was able to do that just like that on my windows machine:
mongod --dbpath ..\..\data\db
You can use a symbolic link as well.
But as already mentioned, a update on users start up script is the best manageable solution.
I would specify the full path from root rather than using the tilde. I'm not sure it can use that.
dbpath = /home/yourusername/mongodb_data