Closed DaNeubi closed 3 years ago
I see two possible (untested) ways:
var collectionSource = db.GetCollection("CollectionName");
var collectionTemp = db.GetCollection("CollectionName_Temp");
var documents = collectionSource.FindAll();
foreach (var document in documents) {
document["_id"] = new BsonValue(document["_id"].AsInt64.ToString());
collectionTemp.Insert(document);
}
db.DropCollection("CollectionName");
db.RenameCollection("CollectionName_Temp", "CollectionName");
Use the "untyped" LiteDbCollection, e.g.:
var collection = db.GetCollection("CollectionName");
var documents = collection.FindAll().ToList();
foreach (var document in documents) {
collection.Delete(document["_id"]);
document["_id"] = new BsonValue(document["_id"].AsInt64.ToString());
collection.Insert(document);
}
Thanks! I used your second method and can confirm it works properly.
You saved me. Thank you so much.
This worked for me. The primary key is an Int64 Public Class ClientRec Public Property ID As Int64 Public Property Name As String End Class
Sub Main() Dim FSDb = New LiteDB.LiteDatabase(DBFileStream) Dim Clients = FSDb.GetCollection(Of ClientRec) Dim Client.EnsureIndex(Of Int64)(Function(x) x.ID) End Sub
Hey there,
I really love your database but just recently can into a problem with my initial setup of the database.
This is my current table structure:
I'd love to change the datatype from System.Int64
_id
to System.StringI'm aware of How do I migrate data structures ? #524, but this issue is a bit old and I can't translate it on my own into the new engine system.
Thanks ahead for any help.