Variable names for designdoc and view in couchdb - python-3.x

New to couchdb. For this hardcoding the name of Design doc and view name works. Is it possible to give a variable for it?
server = couchdb.Server( url)
db = server['test']
for docid in db.view('Res/res'):
i = docid['key']
The above code works but i want to use this code in a loop
i tried the below code. but its giving me error
for docid in db.view(map.cityname+"/"+city):

Related

Firebase Invalid document reference. Document references must have an even number of segments

What is wrong with this query?
const db = firebase.firestore()
const query = db.doc(this.props.user.uid).collection('statements').orderBy('uploadedOn', 'desc').limit(50)
I get the following error:
Uncaught Error: Invalid document reference. Document references must have an even number of segments, but FrMd6Wqch8XJm32HihF14tl6Wui2 has 1
at new FirestoreError (index.cjs.js:346)
at Function.DocumentReference.forPath (index.cjs.js:15563)
at Firestore.doc (index.cjs.js:15368)
at UploadStatementPresentation.componentWillMount (UploadStatementPage.jsx:61)
at UploadStatementPresentation.componentWillMount (createPrototypeProxy.js:44)
at callComponentWillMount (react-dom.development.js:6872)
at mountClassInstance (react-dom.development.js:6968)
at updateClassComponent (react-dom.development.js:8337)
at beginWork (react-dom.development.js:8982)
at performUnitOfWork (react-dom.development.js:11814)
Since you haven't described what exactly you're trying to query, I'll just point out that all documents must be in a collection, without exception. So, if you say this:
db.doc(this.props.user.uid)
Firestore assumes that the string you're passing to doc() contains both the collection and document id separated by a slash. But this seems to be highly unlikely in your case. You need to determine which collection the uid is in, and use that first when you build the reference to the collection you want to query. Assuming that you do have a statements subcollection in the uid document, and that some other collection contains the uid document, you'll have to specify the full path like this:
db.collection('that-other-collection').doc(this.props.user.uid).collection('statements')
Of course, only you know the actual structure of your data.
If you want to get a collection of documents with querying, you don’t have to specify a document id. Below code should work in this case.
const query = db.collection('statements').orderBy('uploadedOn', 'desc').limit(50)
Or if you want to get the document, you can pass the document id to doc() method. In that case, the code should be.
const query = db.collection('statements').doc(this.props.user.uid)
For more details about querying firestorm data: https://firebase.google.com/docs/firestore/query-data/get-data?authuser=0
For others having this issue, make sure that no document reference has an empty string.
I had this issue when using a get method with uid input as below and forgot to check if uid is empty
private fun getFullRef(uid: String): CollectionReference {
return ref.document(uid).collection(FireContact.SUB_PATH)
}

Getting value of key from Web Content Display Portlet

I got a requirement. I have added two text fields Value and Key from structure in Web Content Display portlet.
right now in the portlet i am getting value from hard code like below.
BasicModel model = (BasicModel)requestContext.getFlowScope().get("BasicModel");
if(model == null){
model = new BasicModel();
}
model.setEmployeeId("AB1223344S");
model.setHireDate("01-Jan-2000");
model.setNiNumber("AB123456S");
model.setDateOfBirth("12-Dec-1980");
model.setBasicForm(new BasicDetailsForm());
}
but what i want is to get the value of each attribute from web content. Like, If i have given lfr.intel.empid as key and ABSD1822D as value in the added web content structure field like this.
and we can fetch the value of key like this.
model.setEmployeeId(lfr.intel.empid);
You can write a custom function for this which passes the key to that function, now that function will use the JournalArticleLocalServiceUtil API to get respective value from the DB.
Now you need to find How to fetch values from JournalArticleLocalServiceUtil, which you can google or this link can help you.
Thanks.
Try this, assuming that you could get the JournalArticle object, I've done it using the resourcePrimKey
long resourcePrimKey = 12345; //hard coded the resourcePrimKey
JournalArticle article = JournalArticleLocalServiceUtil.getLatestArticle(resourcePrimKey);
com.liferay.portal.kernel.xml.Document document = SAXReaderUtil.read(article.getContentByLocale("en_US"));
Node keyNode = document.selectSingleNode("/root/dynamic-element[#name='Key']/dynamic-content");
String key = keyNode.getStringValue();
Node valueNode = document.selectSingleNode("/root/dynamic-element[#name='Value']/dynamic-content");
String value = valueNode .getStringValue();

CouchDB "[Circular]" when writing to an array

In CouchDB, I am writing to an array and keep getting the message "[Circular]". I am using Node.js to create the data to be written like this.
Say I have an two email objects in the same document in CouchDB:
unverifiedEmail = [{"address":"john#example.com","dateAdded":"1389215329484"}]
verifiedEmail = []
Now in Node.js I do this before writing.
var oldData = readFromCouchDb();
var newData = oldData;
newData.verifiedEmail.unshift(newData.unverifiedEmail[0]);
writeToCouchDb(newData);
Then when I view the document in Futon I see this:
unverifiedEmail = [{"address":"john#example.com","dateAdded":"1389215329484"}]
verifiedEmail = "[Circular]"
What's going on here?
I found out the issue has to do with the depth of the way to set Javascript objects equal to each other.
To solve this, I used the following code in place of the unshift above:
newData.verifiedEmail.unshift(JSON.parse(JSON.stringify(newData.unverifiedEmail[0])));

XPages #DbLookup returning undefined when looking to another server/database

I am trying to perform an #DbLookup to another server/database and continually receive an "undefined" return message. The database exists, the view name is correct, the key is correct, as well as the column I am trying to return. I have reader access to the database.
I have tried all these combinations for the server/file path, but none seem to work:
var dbName = new Array(session.getServerName(), "my/folder/thisdb.nsf");
var dbName = session.getServerName() + "!!" + my\\folder\\thisdb.nsf;
var dbName = "CN=Server/OU=Name/O=This" + "!!" + my\\folder\\thisdb.nsf;
var dbName = [#DbName([0]), "my/folder/thisdb.nsf"];
I have found this post and tried most of the combinations:
http://www.c-lutions.com/c-lutions/mcblog.nsf/dx/08242012095124AMJMMJ69.htm
Are there any other combinations I can try?
Thanks!
Is your folder's name my folder with a space in it? This could be the challenge. I would suggest to ease your pain....
Create one XPage in your target database, have one computed field on it with #DbName() as formula and see what is coming back. Besides that, your formulas have some issues (comments below the entries):
var dbName = new Array(session.getServerName(), "my/folder/thisdb.nsf");
looks OK unless your folder isn't a subfolder of my. Folders need to be relative to the data directory.
var dbName = session.getServerName() + "!!" + my\\folder\\thisdb.nsf;
dbName must be an array, this one isn't. Also there are no quotes around the file name
var dbName = "CN=Server/OU=Name/O=This" + "!!" + my\\folder\\thisdb.nsf;
same here: must be an array, quote is missing. It is confusing since the data source syntax uses the (CN) format of this: #Name("[CN]";#Subset(#DbName();1)+"!!....
var dbName = [#DbName([0]), "my/folder/thisdb.nsf"];
almost there. #DbName() doesn't take a parameter, so you would write:var dbName = [#DbName()[0], "my/folder/thisdb.nsf"]; or use var dbName = [#Subset(#DbName(),1), "my/folder/thisdb.nsf"];
You also can check great samples to play with.
Make sure the second server is in a trusted server group that is trusted by the first server. For security reasons XPages (and LotusScript) running on any server is unable to access the contents of databases if they are not in the same trusted server group.

Setting author field in SPListItem won't persist

I am trying to copy an SPListItem (with file) from one site collection to another. I do this by creating the file like this:
var archiveFile = newsArchive.Lists[listName].RootFolder.Files.Add(originalItem.File.Name, originalItem.File.OpenBinary());
var archiveItem = archiveFile.Item;
through a utility method I wrote i then set all field values of the new item to correspond with the original item like so
Utilities.PopulateListItemMetadata(....)
The thing is, this does not persist the Author field.
I tried setting the Author field explicitely in every way imaginable, for instance like so:
string userName = originalItem.GetUser("Created by").LoginName;
SPUser user = newsArchive.SiteUsers[userName];
archiveItem["Author"] = user.ID + ";#" + user.LoginName;
archiveItem.Update();
And like so
string userName = originalItem.GetUser("Created by").LoginName;
SPUser user = newsArchive.SiteUsers[userName];
archiveItem["Author"] = user;
archiveItem.Update();
But as soon as the SPListItem.Update() method is called, the archiveItem["Author"] field has reverted to sharepoint\system. I'm a bit at a loss here, this should work..
P.S. the SPListItem.GetUser method is an extension method
P.P.S. Code is being run from a timer job...
Edit: Did some more digging by adding a new field to the content type and then setting that field to reflect the Author of the original item, but that is not set either. However, the web.EnsureUser(username) does return the correct user. Is this weird or what!?!
Found the answer, using
SPFieldUserValue val = new SPFieldUserValue(newsArchive, user.ID, user.Name);
archiveItem["Author"] = val;
archiveItem.SystemUpdate(false);
did the trick!
I've experienced the same problem. Have a look at this question.
The way that worked for me is to wrap the same code you have in your final example in elevated privileges.
Edit
Why don't you try replacing:
SPUser user = newsArchive.SiteUsers[userName];
with:
SPUser user = newsArchive.EnsureUser(userName);
Then you will know the user is in the web and also get a reference to them. The SiteUsers collection gives you the users in the site collection - they have not necessarily been added to the web. If SharePoint doesn't find the user it will probably use system account.

Resources