remove databases with non utf-8 characters in mongodb - mongodb

Good afternoon
How can I remove a database with a non utf-8 character?
See in attach show the database is showed by show dbs command
Thanks for the attention
Regardsenter image description here
Alexandre Bunn

Usually you would do
use [db];
db.dropDatabase();
What the use command actually do is to put the database object to db. With UTF-8 database names you may find it impossible to run the use command. As an alternative way to get the db object, you can run db.getSisterDB([db name]) then drop it.
So this should do the trick:
var db2 = db.getSisterDB(emptyDbs[0].name);
db2.dropDatabase();
There's another method getSiblingDB which returns the same db object. If you are wondering what's the difference between them, well, no difference.
replset:PRIMARY> db.getSiblingDB
function (name) {
return this.getMongo().getDB(name);
}
replset:PRIMARY> db.getSisterDB
function (name) {
return this.getMongo().getDB(name);
}
EDIT:
As the solution above doesn't work for you. I think the last thing you can try is to go to dbpath, find the files named by the UTF-8 characters and delete them. You probably won't file any file under that name. Because when you see (empty) follow a db name, it usually means the db is deleted. If so, just restart the instance would fix the problem.
Remember to stop the database before doing this. And do backup before doing anything.
This way only works for MMAPv1 storage engine.

Related

How to clear or change a message in Redis using powershell?

I am using powershell that is hooked up to jupyter redis rediscommander retwis
I am creating codes like hset snap:msg:4 to "che" from "Dax" text "Is this thing on?"
I made a mistake and msg:3 is meant to be msg:4. Is there any way to clear or edit this message?
Thanks
I have tried lpop but I am new to this and do not understand all the words and what they do yet.
Welcome to StackOverflow!
I made a mistake and msg:3 is meant to be msg:4. Is there any way to clear or edit this message?
You want to rename that key using the RENAME command:
RENAME snap:msg:3 snap:msg:4
How do I just clear everything?
If you wish to remove all the keys in the selected Redis database (caution!) you can do that with the FLUSHDB command. Alternatively, the FLUSHALL command removes all the keys from all the Redis databases (even more caution!).

When shrink litedb files then app cannot find index on <collection>._id. How could i fix it?

I use 3.xx version of litedb and want to shrink the file since it always grows its size.
I shrunk it using LiteDbExplorer's "shrink" button, but now app cannot use this db file.
But still it seems good when using viewer litedbexplorer, litedbviewer, litedbstudio.
I can see data well on these viewers.
but when run application then
it shows
message like "LiteDB.LiteException: Index not found on '<collection_name>._id',
at LiteDB.Query.Run(CollectionPage col, indexService indexer)
at
LiteDB.LiteEngine.<>c__displayClass14_0.b__0(Collectionpage col) ~~~..."
Did I make it broken?
but Index on _id(primary key) and other indexes still exist well.
I check it using "db.collectionname.indexes".
anybody help me through?
It was because of collections' name restriction.
If collection's name is not fit then it cannot manipulate itself, not only its documents.
And also LiteDBExplorer's shrinking function might have some problem.
It does not work always, but LiteDBshell works.
Please use "db.shrink" at shell.
I guess messages like "Invalid format: Collection" at shell can be fixed by changing collection's name.

Jboss server hangs when it try to obtain a connection from HypersonicDB data source

I know cleaning cache will work because tables are cached. But a certain line in my script causing problems here is the content. Please help me understand the line highlighted in bold.
// create table
CREATE CACHED TABLE JMS_MESSAGES(MESSAGEID INTEGER NOT NULL,DESTINATION VARCHAR(255) NOT NULL,TXID INTEGER,TXOP CHAR(1),MESSAGEBLOB OBJECT,PRIMARY KEY(MESSAGEID,DESTINATION))
// create indexes
CREATE INDEX JMS_MESSAGES_TXOP_TXID ON JMS_MESSAGES(TXOP,TXID)
CREATE INDEX JMS_MESSAGES_DESTINATION ON JMS_MESSAGES(DESTINATION)
// what is it doing? because this line makes it hang
SET TABLE JMS_MESSAGES INDEX'3883576 3883576 3883576 0'
Please let me know what this line does so I can debug this script. On production we are using Jboss 4.0.4 and don't often clear tmp/work often and reboot system every Sunday.
Simply delete the line reported in bold and save the .script file with no other change.
The purpose of the line is to link to the data in the .data file. As this is a message cache that is no longer valid, there should be no data there.

Using Powershell after attaching a database, how do you set logical names

I have a standard vanilla database in a folder location, e.g. MyDatabase.mdf, MyDatabases.ldf. My PowerShell script is copying these files to the data folder of SQL Server, and renaming in the process, e.g. MyProject.mdf, MyProject.ldf.
I then attach the databases, however the logical names of both the original vanilla .mdf and .ldf remain. I am unable to figure out how to change these with PowerShell. I can do this with a restore, but wondering how with an attach.
$mdfFileName = "DataFolder\MyProject.mdf"
$ldfFileName = "DataFolder\MyProject.ldf"
$sc = New-Object System.Collections.Specialized.StringCollection
$sc.Add($mdfFileName)
$sc.Add($ldfFileName)
$server.AttachDatabase("MyProject", $sc)
An a test, I have tried
$db.LogFiles[0].Name
and this returns the logical name, however it is only accessible as a getter.
The sample code is missing a lot of functionality. It seems you are using SMO to work with the database. Why not use TSQL instead? It can be executed with Invoke-SqlCmd, or by using System.Data.SqlClient classes from .Net.
CREATE DATABASE [MyProject] ON
(FILENAME = 'some\path\MyProject.mdf'), (FILENAME = 'some\path\MyProject.ldf')
FOR ATTACH;
You can call the rename method to rename the logical file followed by alter method. You'll need to refresh your SMO object with refresh method afterwards to see the changes.

How do I insert a record from one mongo database into another?

As far as I see all commands operate on the same database in mongodb. I want to do something like this:
db.mySourceCollection.find().forEach( function(x){ db.theDestinationCollection.save(x)} );
where mySourceCollection is on liveDatabase and theDestinationCollection is on testDatabase.
Use use :-)
> var documents = db.mySourceCollection.find()
> use testDatabase
switched to db testDatabase
> documents.forEach(function(x){ db.theDestinationCollection.insert(x) })
db is used to refer to the currently connected database, however you can switch databases on the fly using the use command, as I've shown above.
Check out the help command in the shell -- it mentions this command and much more!
use dbname doesn't work in scripted mode (i.e. when scripting the shell with javascript), so you should use the db.getSiblingDB() method instead to reassign the 'db' variable, e.g.:
db = db.getSiblingDB("otherdb")
More info here: http://www.mongodb.org/display/DOCS/Scripting+the+shell